• 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.
  • 💡 We're thrilled to announce that our upcoming texturing contest is in the works, and we're eager to hear your suggestions! Please take this opportunity to share your ideas in this theme discussion thread for the Texturing Contest #34!
  • 🏆 Hive's 7th HD Modeling Contest: Icecrown Creature is now open! The frozen wastes of Icecrown are home to some of Azeroth’s most terrifying and resilient creatures. For this contest, your challenge is to design and model a HD 3D monster that embodies the cold, undead, and sinister essence of Icecrown! 📅 Submissions close on April 13, 2025. Don't miss this opportunity to let your creativity shine! Enter now and show us your frozen masterpiece! 🔗 Click here to enter!

Do dead units eventually get removed from unit groups?

Status
Not open for further replies.
Level 15
Joined
Nov 30, 2007
Messages
1,202
I think they don't. Dead units can also be added into unit groups.

Okey tried to follow a tutorial about group iterations but it doesn't work..

JASS:
    private function OnTimerEnd takes nothing returns nothing
        local unit u 
        loop
            set u = FirstOfGroup(playerHungryUnits[pNum])
            exitwhen u == null
            call GroupRemoveUnit(playerHungryUnits[pNum], u)
            if UnitAlive(u) then
                call BJDebugMsg("readded")
                call GroupAddUnit(swap, u)
            endif
            if pNum == 0 then
                call BJDebugMsg(GetUnitName(u))
            endif
        endloop
        call BJDebugMsg("--------------")

        set temp = playerHungryUnits[pNum]
        set playerHungryUnits[pNum] = swap
        set swap = temp

        if pNum < 12 then 
            set pNum = pNum + 1 
        else 
            set pNum = 0
        endif
    endfunction

It runs twice for player 0 then there apears to be no more units in the group...
 
Level 23
Joined
Apr 16, 2012
Messages
4,041
even removed unit stay inside groups, there is no way for them to be removed, because the underlying representation of unit has no idea about anything called group, and to automatically remove unit from all groups, the unit would need to know all the groups it is in, and then remove itself proprely from them
 
Level 12
Joined
Feb 22, 2010
Messages
1,115
I never seen a shadow unit, so I can't, maybe because I rarely use FirstOfGroup loops.
 
As edo said, shadow references will stay in the unit group's memory. They won't be enumerated with ForGroup(), but FirstOfGroup() loops will eventually hit them--and the unit handle will return null, causing a premature exit. However, you can use something similar to GroupRefresh (link) to get rid of those references.

You can modify GroupRefresh to remove dead units as well. Dead units aren't considered shadow references--not until the game removes them (e.g. after corpse decay), so you can tweak the refresh to remove them sooner.
 
Status
Not open for further replies.
Top