For the longest time I've used a trigger to enable auto suicide on idle units. Fairly simple event,
Unit becomes idle
Unit is special unit
issue order to attack nearest enemy unit in alliance with enemy etc.
But as more specialized units enter the game this trigger gets fired more and more.
I abandoned it for my recent project and just created a behavior that does the same thing. Every second a periodic effect occurs that does a radius 500 search with a max count of 1. On the effect, it issues an order to attack the found unit basing on closest distance to the caster.
I also use 3 validators to disable the behavior so its not going off constantly but only when the unit isn't moving, attacking, or firing weapons.
It works perfectly.
Long story short, here comes the dilemma: Dealing with cloaked units.
In search filters, you need to set the field Visible to required otherwise they will chase cloaked units even when they can't engage them. However if the unit has no enemies visible, you still want it to travel to the nearest closest visible unit.
This is problematic for both trigger and Data solution.
How would you set it up so that even if the unit has no visible units nearby, it will still travel to the next closest unit?
Maybe a Switch Effect? Using two different types of searches based on Enumerate area validators on visible required vs visible allowed and cloak excluded.
Here is my thought process using a switch:
1st search setup Visible required and if it fails, the unit does nothing, goes to second
2nd Search setup Visible allowed but cloak excluded.
The problem then comes, how do you deal with a situation when a cloaked unit becomes visible suddenly? I suppose it would eventually refresh itself if it became idle but in a combat scenario that might not happen when dealing with multiple units. Basically it would engage the cloaked units very last and by that time, they may not actually be visible anymore.
EDIT: I've realized this also has another problem. If you require visible in the enumerate validator for the first search type, then it will attack the closest visible unit, not the closest unit. That could be problematic.
In short the issue is not setting up the suicide, the issue is filters. Remember that if you turn cloaked off, then the unit becomes visible it won't target the cloaked unit until after all regular units are not in range or being engaged.
I'm leaning towards a universal suicide behavior that I can easily implement onto waves of minions and certain spawned units. This eliminates the need for a trigger that runs every time a unit goes idle.
Yes, I want to issue order to retarget the next closest targetable unit. If the unit is cloaked and not visible, then I don't want to target because it will just follow around a cloaked unit, but if the unit is just in the fog of war and is the next closest unit, it should still target it because the minions are auto spawning minions and should "suicide" so they aren't standing around doing nothing, or chasing after the closets visible unit which could be farther away then an actual target that is simply in the "Fog of War".
I also tried visible on Allowed and they still wont auto attack. They will auto attack everything else.
I setup a trigger to make sure the switch is working properly and it is. However, it seems that once you get to the (Cloak Excluded, Visible Excluded) part it just gets stuck on that and the units can't target non visible units regardless of how you set the filters. Only way I can get them to target non visible units is by using Triggers.
Ah I See now, you need to set to Target Point on the issue order! now everything works perfectly!