• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[Solved] Unit groups: temporary or permanent?

Status
Not open for further replies.
Level 4
Joined
Jul 26, 2016
Messages
88
Hey guys,

I was wondering if it is a better practice to, for example, refer to units one is going to pick by for example adding a dummy spell to them and creating a new temp group containing them each iteration of the trigger (not very familiar with timers, so I'm still using Every X second events) or by having a fixed unit group one keeps adding and removing from.

Any thoughts, pros/cons?

Thanks c:
 
Level 11
Joined
Jun 2, 2004
Messages
849
If I parsed that correctly...

Most uses of unit groups I can think of are temporary. Sometimes though you want to keep a set of related units together (like for a fully triggered summon spell or something), and it might be reasonable to keep this data as a unit group. It depends what you're doing. In my current map, the only time I've kept a unit group around longer than the length of a single trigger was to keep track of units targeted by an AoE spell I was triggering.

Notably groups can leak if used improperly, so clean them up every time you create a new one.
 
Level 4
Joined
Jul 26, 2016
Messages
88
@Kaijyuu Well, you know, I've seen people have one global variable for each of their spells. For example, have groupFireball, groupIceSpear etc... Where they never destroy the group, they just loop through it and add/remove units from it. Otherwise you could also: add a dummy spell to desired unit to simulate a unit group, and create a temporary group every time you need it picking all units that have the dummy spell (which is what I've been doing).

My question is more specifically: can I drop creating temporary unit groups and clearing them every time, and just use permanent groups. That way I don't (Do I?) have to worry about leaks, and it's generally nicer on my eyes with fewer lines.

I've been reinstantiating groups every time using the same variable for multiple groups/spells until now because i read somewhere that LOTSA VARIABLES = BAD, but I'm really not so sure about that anymore.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,287
Any thoughts, pros/cons?
refer to units one is going to pick by for example adding a dummy spell to them and creating a new temp group containing them each iteration of the trigger (not very familiar with timers, so I'm still using Every X second events)
This is very inefficient. You iterate through a lot of units every tick applying the filter. If every unit on the map is iterated that can easily end up checking thousands of units to only find under a dozen.

Since the group is rebuilt each frame it is the most simple approach.
by having a fixed unit group one keeps adding and removing from.
This is most efficient. Only the units needed are iterated.

This approach is not as simple as one might think. If the unit is removed (death, triggers etc) then it is not automatically removed from the group, resulting in a form of leak. Additionally a dead unit can be resurrected so simply removing it from the group might result in buggy revived units. One can periodically flush the group, but that is a form of overhead.
 
Status
Not open for further replies.
Top