mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-02-14 19:29:36 +01:00
Fix initialize not getting called for components added during initialize.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -57,6 +57,9 @@ namespace Robust.Shared.GameObjects
|
||||
[ViewVariables]
|
||||
public bool Initialized { get; private set; }
|
||||
|
||||
[ViewVariables]
|
||||
public bool Initializing { get; private set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
[ViewVariables]
|
||||
public bool Deleted { get; private set; }
|
||||
@@ -123,6 +126,7 @@ namespace Robust.Shared.GameObjects
|
||||
/// </summary>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -153,14 +170,6 @@ namespace Robust.Shared.GameObjects
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets up the entity into a valid initial state.
|
||||
/// </summary>
|
||||
public void Initialize()
|
||||
{
|
||||
Initialized = true;
|
||||
}
|
||||
|
||||
#endregion Initialization
|
||||
|
||||
#region Component Messaging
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -34,6 +34,8 @@ namespace Robust.Shared.Interfaces.GameObjects
|
||||
/// </summary>
|
||||
bool Initialized { get; }
|
||||
|
||||
bool Initializing { get; }
|
||||
|
||||
/// <summary>
|
||||
/// True if the entity has been deleted.
|
||||
/// </summary>
|
||||
@@ -193,7 +195,7 @@ namespace Robust.Shared.Interfaces.GameObjects
|
||||
/// <param name="owner"></param>
|
||||
/// <param name="message">Message to send.</param>
|
||||
void SendNetworkMessage(IComponent owner, ComponentMessage message, INetChannel channel = null);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Serverside method to prepare an entity state object
|
||||
/// </summary>
|
||||
|
||||
@@ -195,7 +195,6 @@ namespace Robust.Shared.Map
|
||||
|
||||
var mapComp = newEnt.AddComponent<MapComponent>();
|
||||
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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user