diff --git a/binaries/data/mods/public/simulation/components/UnitAI.js b/binaries/data/mods/public/simulation/components/UnitAI.js index cb5dc7b475..0f0a349100 100644 --- a/binaries/data/mods/public/simulation/components/UnitAI.js +++ b/binaries/data/mods/public/simulation/components/UnitAI.js @@ -3536,7 +3536,6 @@ UnitAI.prototype.SetNextState = function(state) this.UnitFsm.SetNextState(this, state); }; - UnitAI.prototype.DeferMessage = function(msg) { this.UnitFsm.DeferMessage(this, msg); @@ -3592,7 +3591,11 @@ UnitAI.prototype.FinishOrder = function() this.orderQueue = []; this.order = undefined; - this.SetNextState("IDLE"); + + // Switch to IDLE as a default state, but only if our current state is not IDLE + // as this can trigger infinite loops by entering IDLE repeatedly. + if (!this.GetCurrentState().endsWith(".IDLE")) + this.SetNextState("IDLE"); Engine.PostMessage(this.entity, MT_UnitAIOrderDataChanged, { "to": this.GetOrderData() });