So what I had to do to fix this is to hide the unit instead of removing it instantly although I fear than maybe hiding the dying unit may not get removed in the game when the dead unit finished decaying which can cause some lag.
It's fine, you shouldn't be afraid from it.
In fact, you may also consider lowering down their decay time via gameplay constants
if you don't care about bones/corpses. In this way, you have control on their time removal properly.
I just wonder what kind of credit you're about to reward the hero? gold bounty, experience, or something?
It's strange that you're having that kind of problem considering a removed unit
doesn't lose its reference instantly except some 'get' functions would return empty (if not the same time)
I'm also sure gold bounty and experience would execute before a unit removal if there's an actual source.
Just to rule out confusions;
you can get any units using GroupEnumUnitsInRect / OfPlayer which dont care about unit being hidden/locust/dead
GroupEnumUnitsInRect
doesn't enumerate them. How come you considered it?
Or, you're pointing about unit events? such as enters/leaves region? which is obviously true.
locusts can be attacked (when ordered with triggers) by units that have "invulnerable" in allowed targets. it won't do damage, though.
You shouldn't be confused, locust and hidden units are rendered to be 'untargetable'.
They don't fire
EVENT_UNIT_ISSUED_TARGET_ORDER
or
EVENT_PLAYER_UNIT_ISSUED_TARGET_ORDER
For invulnerable units, this is definitely true because they're targetable,
which is also the reason why they're included in the 'Targets' field.
It's a misconception that you can order a unit to target locust or hidden unit.
You'll see the unit moves in their exact position and do nothing doesn't mean the order
is executed via 'target' but in reality it's just replaced as 'target-point'.
For attacks, it's replaced as 'attack-move' instead. Just like how you can 'left-click'
their position as target in-game. As it features two target types: 'unit or point target'.
However, your statement is contrary to locust units but true to invulnerable units.