• 🏆 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!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

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

Not open for further replies.
Level 8
Dec 10, 2006
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
Jan 18, 2005
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.
Not open for further replies.