Index: binaries/data/mods/public/simulation/components/Formation.js =================================================================== --- binaries/data/mods/public/simulation/components/Formation.js +++ binaries/data/mods/public/simulation/components/Formation.js @@ -377,6 +377,10 @@ } } + if (!this.rearrange) + return; + + this.ComputeMotionParameters(); this.MoveMembersIntoFormation(true, true); }; @@ -916,26 +920,16 @@ Formation.prototype.OnGlobalEntityRenamed = function(msg) { - if (this.members.indexOf(msg.entity) != -1) - { - this.offsets = undefined; - var cmpNewUnitAI = Engine.QueryInterface(msg.newentity, IID_UnitAI); - if (cmpNewUnitAI) - { - this.members[this.members.indexOf(msg.entity)] = msg.newentity; - this.memberPositions[msg.newentity] = this.memberPositions[msg.entity]; - } - - var cmpOldUnitAI = Engine.QueryInterface(msg.entity, IID_UnitAI); - cmpOldUnitAI.SetFormationController(INVALID_ENTITY); + if (this.members.indexOf(msg.entity) == -1) + return; - if (cmpNewUnitAI) - cmpNewUnitAI.SetFormationController(this.entity); + // Save rearranging to temporarily set it to false. + let temp = this.rearrange; - // Because the renamed entity might have different characteristics, - // (e.g. packed vs. unpacked siege), we need to recompute motion parameters - this.ComputeMotionParameters(); - } + this.rearrange = false; + this.RemoveMembers([msg.entity]); + this.AddMembers([msg.newentity]); + this.rearrange = temp; }; Formation.prototype.RegisterTwinFormation = function(entity)