• 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.

Units and Unit Group Questions

Status
Not open for further replies.
Level 9
Joined
May 21, 2014
Messages
580
Greetings once again, Hive!

On to my point: I have browsed the questions all over the Internet, but I can't seem to find all the answers I need regarding this.

Let us say I have a unit group UnitGroup. UnitGroup is currently empty.
I add a unit called Unit1 to UnitGroup. Of course, Unit1 will be in UnitGroup. What if Unit1 dies? Will Unit1 still exist in the UnitGroup?
If so, this leads me to another question: If Unit1 really does still exist in UnitGroup, then removing Unit1 from UnitGroup means Unit1 really still exists somewhere, right? If it does exist, how do you remove Unit1 completely?

I ask this because I have to maintain a Unit Group for the AI in the map to have a randomly selected unit to attack within the Unit Group. For example, an enemy type would be commanded to attack the towers first, etc. I want to make sure that data would not leak and overflow to cause a much smoother game.

Thanks, Hive. :ogre_kawaii:
 
Level 26
Joined
Aug 18, 2009
Messages
4,097
Even dead units can be put in a unit group. But you probably refer to removed ones. Units leaving the world do not clean up the references of groups they are in. You either have to check the state of the units you iterate over and should throw unwanted ones out or even better detect the removal of the unit and deregister it from the group in time.
 
Level 9
Joined
May 21, 2014
Messages
580
Thank you for your replies!

about dead units,
they should eventually be deleted after their corpse completely decompose right?

Thanks for this information. I will make sure to remember this.

yes, but they will still be referenced inside groups.

If you do ForGroup, it will automatically evade ghost units(removed units), FirstOfGroup will not.

I do not quite understand, but I think you mean by just removing the unit from a group, right?

Even dead units can be put in a unit group. But you probably refer to removed ones. Units leaving the world do not clean up the references of groups they are in. You either have to check the state of the units you iterate over and should throw unwanted ones out or even better detect the removal of the unit and deregister it from the group in time.

I already have a trigger to remove dying units from the Unit Group using GUI.
That alone is enough, right? They are dead, and they are removed from the Unit Group. Is that already fine?
 
Level 26
Joined
Aug 18, 2009
Messages
4,097
Thanks for this information. I will make sure to remember this.

But it's wrong. The unit is deleted after decomposing but what we addressed here, whether their group memberships are auto-withdrawn, is not the case.

edo494 confirmed this and added that if you iterate over the group via ForGroup (or for GUI users Pick every unit in group and do...), that action ignores bad references, only units that really exist will be accounted for. However, it does not get rid of those bad references. FirstOfGroup on the other hand (not available in GUI) is another option to iterate over a group in combination with GroupRemoveUnit and that afaik fails because FirstOfGroup will give you the bad reference but GroupRemoveUnit does not work then. Also you will have to at least check if the unit is existing since you do not want to run actions on it.

I already have a trigger to remove dying units from the Unit Group using GUI.
That alone is enough, right? They are dead, and they are removed from the Unit Group. Is that already fine?

That is fine if the unit cannot get added after death and if the unit cannot get removed without dying first.
 
Level 9
Joined
May 21, 2014
Messages
580
But it's wrong. The unit is deleted after decomposing but what we addressed here, whether their group memberships are auto-withdrawn, is not the case.

edo494 confirmed this and added that if you iterate over the group via ForGroup (or for GUI users Pick every unit in group and do...), that action ignores bad references, only units that really exist will be accounted for. However, it does not get rid of those bad references. FirstOfGroup on the other hand (not available in GUI) is another option to iterate over a group in combination with GroupRemoveUnit and that afaik fails because FirstOfGroup will give you the bad reference but GroupRemoveUnit does not work then. Also you will have to at least check if the unit is existing since you do not want to run actions on it.



That is fine if the unit cannot get added after death and if the unit cannot get removed without dying first.

I see! I can finally grasp on the idea of it slowly. I wanted to make sure what you really mean on your last statement. I quite don't get it clearly.
From what I understand, the unit needs to die first, then remove it from the Unit Group, and that the dead unit must not in any way get added to any unit groups. Is that it?
 
Last edited:
Level 26
Joined
Aug 18, 2009
Messages
4,097
Alive or dead state of a unit does not matter in regards to the membership inside a group. You can add/remove them anytime. But to avoid bad references, which come to surface when a unit disappears while still having remaining memberships, you have to revoke those memberships before it comes to this event. If you can logically guarantee this condition, you do not have to exactly do it just when the unit disappears.
 
Level 9
Joined
May 21, 2014
Messages
580
Alive or dead state of a unit does not matter in regards to the membership inside a group. You can add/remove them anytime. But to avoid bad references, which come to surface when a unit disappears while still having remaining memberships, you have to revoke those memberships before it comes to this event. If you can logically guarantee this condition, you do not have to exactly do it when the unit disappears.

Ack! Now that you mention it, maybe I need to share my trigger.

My Trigger's event is "A UNIT DIES"

Then I check IF THE DYING UNIT IS IN UNIT GROUP, THEN REMOVE THE DYING UNIT.

Will this cause bad references?
 
Level 9
Joined
May 21, 2014
Messages
580
I repeat. Even dead units can be added to unit groups and I do not know if you do this.

Secondly, I do not know if there are any means inside your map to make a unit disppear without killing it. Like if you directly use RemoveUnit on a living unit, ofc it will not trigger your dying event.

Ah! I get what you mean now. I ensure that the unit is "killed". I am also confident that dead units can't be added to any Unit Groups.

Thanks for the help, guys!
 
Status
Not open for further replies.
Top