From 1db982276ae02b498cedbc5008b5145ad27ee8c0 Mon Sep 17 00:00:00 2001 From: Gustas <37534529+PunkPun@users.noreply.github.com> Date: Wed, 12 Apr 2023 13:49:58 +0300 Subject: [PATCH] Fix actors being added to world while world actors are being iterated --- .../Scripting/Global/ReinforcementsGlobal.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/OpenRA.Mods.Common/Scripting/Global/ReinforcementsGlobal.cs b/OpenRA.Mods.Common/Scripting/Global/ReinforcementsGlobal.cs index 7c396c18f7..b97ae916e7 100644 --- a/OpenRA.Mods.Common/Scripting/Global/ReinforcementsGlobal.cs +++ b/OpenRA.Mods.Common/Scripting/Global/ReinforcementsGlobal.cs @@ -55,7 +55,12 @@ namespace OpenRA.Mods.Common.Scripting initDict.Add(new FacingInit(facing)); } - return Context.World.CreateActor(addToWorld, actorType, initDict); + // The actor must be added to the world at the end of the tick. + var a = Context.World.CreateActor(false, actorType, initDict); + if (addToWorld) + Context.World.AddFrameEndTask(w => w.Add(a)); + + return a; } void Move(Actor actor, CPos dest)