diff --git a/OpenRA.Game/Actor.cs b/OpenRA.Game/Actor.cs index 17a1781a97..258fc34376 100644 --- a/OpenRA.Game/Actor.cs +++ b/OpenRA.Game/Actor.cs @@ -172,7 +172,7 @@ namespace OpenRA SyncHashes = TraitsImplementing().Select(sync => new SyncHash(sync)).ToArray(); } - internal void Created() + internal void Initialize(bool addToWorld = true) { created = true; @@ -226,6 +226,9 @@ namespace OpenRA activity.Queue(CurrentActivity); CurrentActivity = activity; } + + if (addToWorld) + World.Add(this); } public void Tick() diff --git a/OpenRA.Game/Player.cs b/OpenRA.Game/Player.cs index dda05e658e..5752bfd80a 100644 --- a/OpenRA.Game/Player.cs +++ b/OpenRA.Game/Player.cs @@ -169,12 +169,11 @@ namespace OpenRA // Special case handling is required for the Player actor: // Since Actor.Created would be called before PlayerActor is assigned here // querying player traits in INotifyCreated.Created would crash. - // Therefore only call the constructor of Actor and run the Created callbacks ourselves. - // Add the PlayerActor to the world afterwards. + // Therefore assign the uninitialized actor and run the Created callbacks + // by calling Initialize ourselves. var playerActorType = world.Type == WorldType.Editor ? EditorPlayerActorType : PlayerActorType; PlayerActor = new Actor(world, playerActorType, new TypeDictionary { new OwnerInit(this) }); - PlayerActor.Created(); - world.Add(PlayerActor); + PlayerActor.Initialize(true); Shroud = PlayerActor.Trait(); FrozenActorLayer = PlayerActor.TraitOrDefault(); diff --git a/OpenRA.Game/World.cs b/OpenRA.Game/World.cs index eac9cf9ed7..df51498ed5 100644 --- a/OpenRA.Game/World.cs +++ b/OpenRA.Game/World.cs @@ -337,10 +337,7 @@ namespace OpenRA public Actor CreateActor(bool addToWorld, string name, TypeDictionary initDict) { var a = new Actor(this, name, initDict); - a.Created(); - if (addToWorld) - Add(a); - + a.Initialize(addToWorld); return a; }