/// <summary> /// Allocates an entity and loads components but does not do initialization. /// </summary> private protected Entity CreateEntity(string prototypeName, EntityUid?uid = null) { if (prototypeName == null) { return(AllocEntity(uid)); } var entity = AllocEntity(prototypeName, uid); EntityPrototype.LoadEntity(entity.Prototype, entity, ComponentFactory, null); return(entity); }
/// <summary> /// Allocates an entity and stores it but does not load components or do initialization. /// </summary> private protected Entity AllocEntity(string prototypeName, EntityUid?uid = null) { EntityPrototype prototype = null; if (!string.IsNullOrWhiteSpace(prototypeName)) { // If the prototype doesn't exist then we throw BEFORE we allocate the entity. prototype = PrototypeManager.Index <EntityPrototype>(prototypeName); } var entity = AllocEntity(uid); entity.Prototype = prototype; return(entity); }
/// <summary> /// Allocates an entity and loads components but does not do initialization. /// </summary> private protected Entity CreateEntity(string prototypeName, EntityUid?uid = null) { if (prototypeName == null) { return(AllocEntity(uid)); } var entity = AllocEntity(prototypeName, uid); try { EntityPrototype.LoadEntity(entity.Prototype, entity, ComponentFactory, null); return(entity); } catch (Exception e) { // Exception during entity loading. // Need to delete the entity to avoid corrupt state causing crashes later. DeleteEntity(entity); throw new EntityCreationException("Exception inside CreateEntity", e); } }
private protected void LoadEntity(Entity entity, IEntityLoadContext context) { EntityPrototype.LoadEntity(entity.Prototype, entity, ComponentFactory, context); }