diff --git a/Robust.Server/GameObjects/ServerEntityManager.cs b/Robust.Server/GameObjects/ServerEntityManager.cs index 1ab615fb8..8eddce145 100644 --- a/Robust.Server/GameObjects/ServerEntityManager.cs +++ b/Robust.Server/GameObjects/ServerEntityManager.cs @@ -69,21 +69,29 @@ namespace Robust.Server.GameObjects if (!string.IsNullOrWhiteSpace(prototypeName)) { - var prototype = PrototypeManager.Index(prototypeName); - - // At this point in time, all data configure on the entity *should* be purely from the prototype. - // As such, we can reset the modified ticks to Zero, - // which indicates "not different from client's own deserialization". - // So the initial data for the component or even the creation doesn't have to be sent over the wire. - foreach (var (netId, component) in GetNetComponents(entity.Uid)) + if (PrototypeManager.TryIndex(prototypeName, out var prototype)) { - // Make sure to ONLY get components that are defined in the prototype. - // Others could be instantiated directly by AddComponent (e.g. ContainerManager). - // And those aren't guaranteed to exist on the client, so don't clear them. - if (prototype.Components.ContainsKey(component.Name)) ((Component) component).ClearTicks(); + + // At this point in time, all data configure on the entity *should* be purely from the prototype. + // As such, we can reset the modified ticks to Zero, + // which indicates "not different from client's own deserialization". + // So the initial data for the component or even the creation doesn't have to be sent over the wire. + foreach (var (netId, component) in GetNetComponents(entity.Uid)) + { + // Make sure to ONLY get components that are defined in the prototype. + // Others could be instantiated directly by AddComponent (e.g. ContainerManager). + // And those aren't guaranteed to exist on the client, so don't clear them. + if (prototype.Components.ContainsKey(component.Name)) ((Component) component).ClearTicks(); + } + } + else + { + Logger.Error($"Invalid prototypeId '{prototypeName}' passed to {nameof(CreateEntity)}."); } } + + return entity; } diff --git a/Robust.Shared/GameObjects/EntityManager.cs b/Robust.Shared/GameObjects/EntityManager.cs index df42531ec..de9a755dc 100644 --- a/Robust.Shared/GameObjects/EntityManager.cs +++ b/Robust.Shared/GameObjects/EntityManager.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Linq; using Prometheus; +using Robust.Shared.Log; using Robust.Shared.Map; using Robust.Shared.Prototypes; using Robust.Shared.Timing; @@ -349,10 +350,9 @@ namespace Robust.Shared.GameObjects private protected Entity AllocEntity(string? prototypeName, EntityUid? uid = null) { EntityPrototype? prototype = null; - if (!string.IsNullOrWhiteSpace(prototypeName)) + if(!string.IsNullOrWhiteSpace(prototypeName) && !PrototypeManager.TryIndex(prototypeName, out prototype)) { - // If the prototype doesn't exist then we throw BEFORE we allocate the entity. - prototype = PrototypeManager.Index(prototypeName); + Logger.Error($"Invalid prototypeId '{prototypeName}' passed to {nameof(AllocEntity)}."); } var entity = AllocEntity(uid); @@ -405,7 +405,7 @@ namespace Robust.Shared.GameObjects /// private protected virtual Entity CreateEntity(string? prototypeName, EntityUid? uid = null) { - if (prototypeName == null) + if (!string.IsNullOrWhiteSpace(prototypeName)) return AllocEntity(uid); var entity = AllocEntity(prototypeName, uid);