diff --git a/Robust.Shared/GameObjects/ComponentManager.cs b/Robust.Shared/GameObjects/ComponentManager.cs index b21c62d3b..29f6e3d69 100644 --- a/Robust.Shared/GameObjects/ComponentManager.cs +++ b/Robust.Shared/GameObjects/ComponentManager.cs @@ -129,10 +129,14 @@ namespace Robust.Shared.GameObjects component.OnAdd(); - if (entity.Initialized) + if (entity.Initialized || entity.Initializing) { component.Initialize(); - component.Running = true; + + if (entity.Initialized) + { + component.Running = true; + } } } diff --git a/Robust.Shared/GameObjects/Entity.cs b/Robust.Shared/GameObjects/Entity.cs index be052df63..8a9d448a2 100644 --- a/Robust.Shared/GameObjects/Entity.cs +++ b/Robust.Shared/GameObjects/Entity.cs @@ -57,6 +57,9 @@ namespace Robust.Shared.GameObjects [ViewVariables] public bool Initialized { get; private set; } + [ViewVariables] + public bool Initializing { get; private set; } + /// [ViewVariables] public bool Deleted { get; private set; } @@ -123,6 +126,7 @@ namespace Robust.Shared.GameObjects /// public void InitializeComponents() { + Initializing = true; // Initialize() can modify the collection of components. var components = EntityManager.ComponentManager.GetComponents(Uid); foreach (var t in components) @@ -135,6 +139,19 @@ namespace Robust.Shared.GameObjects DebugTools.Assert(comp.Initialized, $"Component {comp.Name} did not call base {nameof(comp.Initialize)} in derived method."); } } + + #if DEBUG + + // Second integrity check in case of. + foreach (var t in EntityManager.ComponentManager.GetComponents(Uid)) + { + DebugTools.Assert(t.Initialized, $"Component {t.Name} was not initialized at the end of {nameof(InitializeComponents)}."); + } + + #endif + + Initialized = true; + Initializing = false; } /// @@ -153,14 +170,6 @@ namespace Robust.Shared.GameObjects } } - /// - /// Sets up the entity into a valid initial state. - /// - public void Initialize() - { - Initialized = true; - } - #endregion Initialization #region Component Messaging diff --git a/Robust.Shared/GameObjects/EntityManager.cs b/Robust.Shared/GameObjects/EntityManager.cs index 49cd95a6e..c0328facf 100644 --- a/Robust.Shared/GameObjects/EntityManager.cs +++ b/Robust.Shared/GameObjects/EntityManager.cs @@ -296,7 +296,6 @@ namespace Robust.Shared.GameObjects private protected static void InitializeEntity(Entity entity) { entity.InitializeComponents(); - entity.Initialize(); } private protected static void StartEntity(Entity entity) diff --git a/Robust.Shared/Interfaces/GameObjects/IEntity.cs b/Robust.Shared/Interfaces/GameObjects/IEntity.cs index 473775f91..c420c6f19 100644 --- a/Robust.Shared/Interfaces/GameObjects/IEntity.cs +++ b/Robust.Shared/Interfaces/GameObjects/IEntity.cs @@ -34,6 +34,8 @@ namespace Robust.Shared.Interfaces.GameObjects /// bool Initialized { get; } + bool Initializing { get; } + /// /// True if the entity has been deleted. /// @@ -193,7 +195,7 @@ namespace Robust.Shared.Interfaces.GameObjects /// /// Message to send. void SendNetworkMessage(IComponent owner, ComponentMessage message, INetChannel channel = null); - + /// /// Serverside method to prepare an entity state object /// diff --git a/Robust.Shared/Map/MapManager.cs b/Robust.Shared/Map/MapManager.cs index c2527ad5a..f623e520b 100644 --- a/Robust.Shared/Map/MapManager.cs +++ b/Robust.Shared/Map/MapManager.cs @@ -195,7 +195,6 @@ namespace Robust.Shared.Map var mapComp = newEnt.AddComponent(); mapComp.WorldMap = actualID; - newEnt.Initialize(); newEnt.InitializeComponents(); newEnt.StartAllComponents(); Logger.DebugS("map", $"Binding map {actualID} to entity {newEnt.Uid}"); @@ -303,7 +302,6 @@ namespace Robust.Shared.Map newEnt.Transform.AttachParent(_entityManager.GetEntity(_mapEntities[currentMapID])); - newEnt.Initialize(); newEnt.InitializeComponents(); newEnt.StartAllComponents(); }