What happens with unit in array when its removed from the game?

Level 5
Joined
May 10, 2024
Messages
57
Hello!

I have an array of Units with initial value set to noUnit. I want to detect removed unit while iterating over array.

As far as I know unit can be removed by the engine after decay or by using Unit - Remove() function. Methods below is not working:

1. GUI unit comparison unitArray[unitIndex] equal to No Unit
2. JASS if udg_unitArray[udg_unitIndex] == null then

What happens to unit in array in such situations?
 

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,866
Hello!

I have an array of Units with initial value set to noUnit. I want to detect removed unit while iterating over array.

As far as I know unit can be removed by the engine after decay or by using Unit - Remove() function. Methods below is not working:

1. GUI unit comparison unitArray[unitIndex] equal to No Unit
2. JASS if udg_unitArray[udg_unitIndex] == null then

What happens to unit in array in such situations?
See Dr's last comment:

Either manually null the units at the time of decay/removing them or you can rely on something like this to detect a removed unit:
vJASS:
if GetUnitTypeId(yourUnit) == 0 then
 // It's been removed from the game
endif
 
Top