diff --git a/binaries/data/mods/public/simulation/components/UnitAI.js b/binaries/data/mods/public/simulation/components/UnitAI.js index 494edafa07..5d5ac89fb8 100644 --- a/binaries/data/mods/public/simulation/components/UnitAI.js +++ b/binaries/data/mods/public/simulation/components/UnitAI.js @@ -2564,18 +2564,9 @@ UnitAI.prototype.OnOwnershipChanged = function(msg) UnitAI.prototype.OnDestroy = function() { - // Clean up any timers that are now obsolete - this.StopTimer(); + // Switch to an empty state to let states execute their leave handlers. + UnitFsm.SwitchToNextState(this, ""); - // clear up the ResourceSupply gatherer count. - if (this.gatheringTarget) - { - var cmpSupply = Engine.QueryInterface(this.gatheringTarget, IID_ResourceSupply); - if (cmpSupply) - cmpSupply.RemoveGatherer(this.entity); - delete this.gatheringTarget; - } - // Clean up range queries var rangeMan = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager); if (this.losRangeQuery) diff --git a/binaries/data/mods/public/simulation/helpers/FSM.js b/binaries/data/mods/public/simulation/helpers/FSM.js index 1cc52ce735..05271b8198 100644 --- a/binaries/data/mods/public/simulation/helpers/FSM.js +++ b/binaries/data/mods/public/simulation/helpers/FSM.js @@ -350,7 +350,7 @@ FSM.prototype.SwitchToNextState = function(obj, nextStateName) } // Check if we should exit and enter the current state due to the reenter parameter. If so we go up 1 level - if (obj.fsmReenter && equalPrefix === toState.length) + if (obj.fsmReenter && equalPrefix > 0 && equalPrefix === toState.length) --equalPrefix; for (var i = fromState.length-1; i >= equalPrefix; --i)