diff --git a/Robust.Shared/GameObjects/IMapInit.cs b/Robust.Shared/GameObjects/IMapInit.cs index 0ce9ca953..7bc41eb2f 100644 --- a/Robust.Shared/GameObjects/IMapInit.cs +++ b/Robust.Shared/GameObjects/IMapInit.cs @@ -29,7 +29,11 @@ namespace Robust.Shared.GameObjects { var entMan = IoCManager.Resolve(); var meta = entMan.GetComponent(entity); - DebugTools.Assert(meta.EntityLifeStage == EntityLifeStage.Initialized); + + if (meta.EntityLifeStage == EntityLifeStage.MapInitialized) + return; // Already map initialized, do nothing. + + DebugTools.Assert(meta.EntityLifeStage == EntityLifeStage.Initialized, $"Expected entity {entMan.ToPrettyString(entity)} to be initialized, was {meta.EntityLifeStage}"); meta.EntityLifeStage = EntityLifeStage.MapInitialized; entMan.EventBus.RaiseLocalEvent(entity, MapInit, false); diff --git a/Robust.Shared/Timing/PauseManager.cs b/Robust.Shared/Timing/PauseManager.cs index eb8a8d4a1..599421cd3 100644 --- a/Robust.Shared/Timing/PauseManager.cs +++ b/Robust.Shared/Timing/PauseManager.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Globalization; +using System.Linq; using Robust.Shared.Console; using Robust.Shared.GameObjects; using Robust.Shared.IoC; @@ -49,10 +50,13 @@ namespace Robust.Shared.Timing _unInitializedMaps.Remove(mapId); - foreach (var entity in IoCManager.Resolve().GetEntitiesInMap(mapId)) + foreach (var entity in IoCManager.Resolve().GetEntitiesInMap(mapId).ToArray()) { entity.RunMapInit(); - _entityManager.GetComponent(entity).EntityPaused = false; + + // MapInit could have deleted this entity. + if(_entityManager.TryGetComponent(entity, out MetaDataComponent? meta)) + meta.EntityPaused = false; } } diff --git a/Robust.UnitTesting/Server/Maps/MapLoaderTest.cs b/Robust.UnitTesting/Server/Maps/MapLoaderTest.cs index 854df7960..47cbb4a69 100644 --- a/Robust.UnitTesting/Server/Maps/MapLoaderTest.cs +++ b/Robust.UnitTesting/Server/Maps/MapLoaderTest.cs @@ -101,6 +101,7 @@ entities: protoMan.RegisterType(typeof(EntityPrototype)); protoMan.LoadDirectory(new ResourcePath("/Prototypes")); + protoMan.Resync(); } [Test] diff --git a/Robust.UnitTesting/Shared/Serialization/InheritanceSerializationTest.cs b/Robust.UnitTesting/Shared/Serialization/InheritanceSerializationTest.cs index 1e64f257c..1942d4f3b 100644 --- a/Robust.UnitTesting/Shared/Serialization/InheritanceSerializationTest.cs +++ b/Robust.UnitTesting/Shared/Serialization/InheritanceSerializationTest.cs @@ -60,6 +60,7 @@ namespace Robust.UnitTesting.Shared.Serialization prototypeManager.RegisterType(typeof(EntityPrototype)); prototypeManager.LoadString(Prototypes); + prototypeManager.Resync(); var entityManager = IoCManager.Resolve();