Class EntityManager
A manager for creating, destroying, and managing entities and their components.
public class EntityManager : IDisposable
- Inheritance
-
EntityManager
- Implements
- Inherited Members
Remarks
All methods in this class are not thread-safe and all of them will cause structural changes if not mentioned otherwise. Use EntityCommandBuffer to defer structural changes to a safe point. Use GetThreadLocalEntityCommandBuffer(int) to get a thread-local command buffer for multithreaded scenarios.
Properties
World
public World World { get; }
Property Value
Methods
AddComponent(Entity, Identifier<IComponent>, void*)
Add a component to the specified entity.
public Error AddComponent(Entity entity, Identifier<IComponent> componentID, void* pComponent)
Parameters
entityEntityThe entity to add the component to.
componentIDIdentifier<IComponent>The component space ID to add.
pComponentvoid*Pointer to the component data.
Returns
- Error
The result status of the operation.
AddComponent<T>(Entity, T)
Add a component to the specified entity.
public Error AddComponent<T>(Entity entity, T component = default) where T : unmanaged, IComponent
Parameters
entityEntityThe entity to add the component to.
componentTThe component data.
Returns
- Error
The result status of the operation.
Type Parameters
TThe component space.
AddScriptComponent<T>(Entity)
Adds a ScriptComponent of space T to the given Entity.
public void AddScriptComponent<T>(Entity entity) where T : ScriptComponent, new()
Parameters
entityEntityThe Entity to add the ScriptComponent to.
Type Parameters
TThe space of ScriptComponent to add.
AddScriptComponent<T>(ManagedEntity, Entity)
public void AddScriptComponent<T>(ManagedEntity managedEntity, Entity entity) where T : ScriptComponent, new()
Parameters
managedEntityManagedEntityentityEntity
Type Parameters
T
CreateEntities(int)
Create multiple entities with no components.
public void CreateEntities(int count)
Parameters
countintThe number of entities to create.
CreateEntities(int, ComponentSet)
Create multiple entities with specified components.
public void CreateEntities(int count, ComponentSet set)
Parameters
countintThe number of entities to create.
setComponentSetA set of component space IDs to add to the entities.
CreateEntities(Span<Entity>)
Create multiple entities with no components.
public void CreateEntities(Span<Entity> entities)
Parameters
CreateEntities(Span<Entity>, ComponentSet)
Create multiple entities with specified components.
public void CreateEntities(Span<Entity> entities, ComponentSet set)
Parameters
entitiesSpan<Entity>The span to store the created entities.
setComponentSetA set of component space IDs to add to the entities.
CreateEntity()
Create an entity with no components.
public Entity CreateEntity()
Returns
- Entity
The created entity.
CreateEntity(ComponentSet)
Create an entity with specified components.
public Entity CreateEntity(ComponentSet set)
Parameters
setComponentSetA set of component space IDs to add to the entities.
Returns
- Entity
The created entity.
CreateManagedEntity()
Creates a new ManagedEntity.
public ManagedEntity CreateManagedEntity()
Returns
- ManagedEntity
The created ManagedEntity.
Remarks
You must call this if you add ManagedEntityRef manually to an entity. Otherwise, use CreateManagedEntity(Entity).
CreateManagedEntity(Entity)
Creates a new ManagedEntity and associates it with the given Entity.
public ManagedEntity CreateManagedEntity(Entity entity)
Parameters
entityEntityThe Entity to associate with the ManagedEntity.
Returns
- ManagedEntity
The created ManagedEntity.
CreateSingleton(Identifier<IComponent>, void*)
Create a singleton entity with the specified component.
public Error CreateSingleton(Identifier<IComponent> componentID, void* pComponent)
Parameters
componentIDIdentifier<IComponent>The component space ID of the singleton.
pComponentvoid*Pointer to the component data.
Returns
- Error
The result status of the operation.
CreateSingleton<T>(T)
Create a singleton entity with the specified component.
public Error CreateSingleton<T>(T component = default) where T : unmanaged, IComponent
Parameters
componentTThe component data.
Returns
- Error
The result status of the operation.
Type Parameters
TThe component space.
DestroyEntities(ReadOnlySpan<Entity>)
Destroy the specified entities.
public void DestroyEntities(ReadOnlySpan<Entity> entities)
Parameters
entitiesReadOnlySpan<Entity>The entities to destroy.
DestroyEntity(Entity)
Destroy the specified entity.
public Error DestroyEntity(Entity entity)
Parameters
entityEntity
Returns
- Error
The result status of the operation.
DestroyManagedEntity(ManagedEntity)
Destroys the given ManagedEntity and calls OnDestroy on all associated ScriptComponents.
public void DestroyManagedEntity(ManagedEntity managedEntity)
Parameters
managedEntityManagedEntityThe ManagedEntity to destroy.
DestroyScriptComponent<T>(ManagedEntity)
public bool DestroyScriptComponent<T>(ManagedEntity managedEntity) where T : ScriptComponent
Parameters
managedEntityManagedEntity
Returns
Type Parameters
T
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
public void Dispose()
Exists(Entity)
Check if the specified entity exists.
public bool Exists(Entity entity)
Parameters
entityEntityThe entity to check.
Returns
- bool
True if the entity exists, false otherwise.
Exists(ManagedEntity)
Checks if the given ManagedEntity exists.
public bool Exists(ManagedEntity managedEntity)
Parameters
managedEntityManagedEntityThe ManagedEntity to check.
Returns
- bool
True if the ManagedEntity exists, false otherwise.
~EntityManager()
protected ~EntityManager()
GetComponent(Entity, Identifier<IComponent>)
Get a pointer to the component data for the specified entity.
public void* GetComponent(Entity entity, Identifier<IComponent> componentID)
Parameters
entityEntityThe entity to get the component data for.
componentIDIdentifier<IComponent>The component space ID to get.
Returns
- void*
Pointer to the component data, or null if not found.
GetComponent<T>(Entity)
Get a reference to the component data for the specified entity.
public ref T GetComponent<T>(Entity entity) where T : unmanaged, IComponent
Parameters
entityEntityThe entity to get the component data for.
Returns
- T
Reference to the component data. null ref if not found.
Type Parameters
TThe component space.
GetScriptComponent<T>(ManagedEntity)
public T GetScriptComponent<T>(ManagedEntity managedEntity) where T : ScriptComponent
Parameters
managedEntityManagedEntity
Returns
- T
Type Parameters
T
GetScriptComponents<T>(ManagedEntity)
public List<T> GetScriptComponents<T>(ManagedEntity managedEntity) where T : ScriptComponent
Parameters
managedEntityManagedEntity
Returns
- List<T>
Type Parameters
T
GetSingleton(Identifier<IComponent>)
Get a pointer to the singleton component data.
public void* GetSingleton(Identifier<IComponent> componentID)
Parameters
componentIDIdentifier<IComponent>The component space ID of the singleton.
Returns
- void*
Pointer to the component data, or null if not found.
GetSingleton<T>()
Get a reference to the singleton component data.
public ref T GetSingleton<T>() where T : unmanaged, IComponent
Returns
- T
Reference to the component data. null ref if not found.
Type Parameters
TThe component space.
HasComponent(Entity, Identifier<IComponent>)
Check if the specified entity has the specified component.
public bool HasComponent(Entity entity, Identifier<IComponent> componentID)
Parameters
entityEntityThe entity to check.
componentIDIdentifier<IComponent>The component space ID to check.
Returns
- bool
True if the entity has the component, false otherwise.
HasComponent<T>(Entity)
Check if the specified entity has the specified component.
public bool HasComponent<T>(Entity entity) where T : unmanaged, IComponent
Parameters
entityEntityThe entity to check.
Returns
- bool
True if the entity has the component, false otherwise.
Type Parameters
TThe component space.
HasScriptComponent<T>(ManagedEntity)
Checks if the given ManagedEntity has a ScriptComponent of space T.
public bool HasScriptComponent<T>(ManagedEntity managedEntity) where T : ScriptComponent
Parameters
managedEntityManagedEntityThe ManagedEntity to check.
Returns
- bool
True if the ManagedEntity has a ScriptComponent of space T, false
Type Parameters
TThe space of ScriptComponent to check for.
RemoveComponent(Entity, Identifier<IComponent>)
Remove a component from the specified entity.
public Error RemoveComponent(Entity entity, Identifier<IComponent> componentID)
Parameters
entityEntityThe entity to remove the component from.
componentIDIdentifier<IComponent>The component space ID to remove.
Returns
- Error
The result status of the operation.
RemoveComponent<T>(Entity)
Remove a component from the specified entity.
public Error RemoveComponent<T>(Entity entity) where T : unmanaged, IComponent
Parameters
entityEntityThe entity to remove the component from.
Returns
- Error
The result status of the operation.
Type Parameters
TThe component space.
SetComponent(Entity, Identifier<IComponent>, void*)
Set the component data for the specified entity.
public Error SetComponent(Entity entity, Identifier<IComponent> componentID, void* pComponent)
Parameters
entityEntityThe entity to set the component data for.
componentIDIdentifier<IComponent>The component space ID to set.
pComponentvoid*Pointer to the component data.
Returns
- Error
The result status of the operation.
SetComponent<T>(Entity, T)
Set the component data for the specified entity.
public Error SetComponent<T>(Entity entity, T component) where T : unmanaged, IComponent
Parameters
entityEntityThe entity to set the component data for.
componentTThe component data.
Returns
- Error
Type Parameters
TThe component space.
SetEnabled(Entity, Identifier<IComponent>, bool)
public Error SetEnabled(Entity entity, Identifier<IComponent> componentID, bool enabled)
Parameters
entityEntitycomponentIDIdentifier<IComponent>enabledbool
Returns
- Error
SetEnabled<T>(Entity, bool)
public Error SetEnabled<T>(Entity entity, bool enabled) where T : unmanaged, IEnableableComponent
Parameters
Returns
- Error
Type Parameters
T