• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • ✅ The POLL for Hive's Texturing Contest #33 is OPEN! Vote for the TOP 3 SKINS! 🔗Click here to cast your vote!

[Trigger] Should a unit be removed from a unit group if its dead

Status
Not open for further replies.
Level 8
Joined
Dec 10, 2006
Messages
67
If you're doing a Pick Every Unit In Group operation it will be included unless you include a specific condition where the Matching Unit isn't alive. If the fact that it's dead means that it is no longer relevant, some computer time, as miniscule as it might seem, will be wasted dealing with it. If you know what group or groups a given unit is in or might be in, you should probably remove the unit from the group or groups upon death. One thing I often do is if a PEUiG op is used on a particular group multiple times is include an If/Then/Else within the Pick Every Unit In Group loop that checks if the Picked Unit is still alive and still within the map rect. If both are true, the unit is processed. If not, I remove the Picked Unit from the group. By the way, dude, this thread probably belongs in the World Editor Help Zone.
 
Last edited:
Not only that, but removed units will also remain in your group unless removed from the group manually.

This is called "shadow reference". The GUI action "Pick every unit in group" will not consider these "null" units, but it will slow down the pick function if too many shadow references are in your group.

So yes, it is always a very good practice to remove dying units from all groups they belong to.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,233
If the unit group is referenced in the future will the dead unit be part of it?
Yes however once the unit is removed (after decay or with trigger action) then it will be considered "null" (no unit).

Is this a problem and will it cause lag?
Yes it is a problem and it can result in bad performance. Once a group reaches a certain size certain actions degrade in performance on it (takes more time to execute).

You can either manually remove units from groups, automatically remove units from groups or occasionally compact the group.

Manually is when on death you remove them from the group. If you remove them with triggers you remove them from the group before. If they are in multiple groups then you remove them from each group.

Automatically removing units would be with some form of hashtable system. You use a custom function to add a unit to a group which uses the hashtable to record a list of which group the unit was added to. You then have an on-death event that removes them from the groups. You also have a custom remove function which removes the unit and before then removes it from all groups. Remember to flush hashtable entries which are no longer needed to prevent mapping leaks in the hashtable.

The final approach is you let removed units remain in the group but every so often you flush it. This is done by transferring the units to a new clean group and discarding null values. You can then clear the old group (which sets it back to initial state) and swap in the new group for the variable. The old group can be re-cycles as the new group for the next swap procedure or could be removed if desired.
 
Status
Not open for further replies.
Top