Table of Contents

Class EntityManager

Namespace
Ghost.Entities
Assembly
Ghost.Entities.dll

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

World

Methods

AddComponent(Entity, Identifier<IComponent>, void*)

Add a component to the specified entity.

public Error AddComponent(Entity entity, Identifier<IComponent> componentID, void* pComponent)

Parameters

entity Entity

The entity to add the component to.

componentID Identifier<IComponent>

The component space ID to add.

pComponent void*

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

entity Entity

The entity to add the component to.

component T

The component data.

Returns

Error

The result status of the operation.

Type Parameters

T

The 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

entity Entity

The Entity to add the ScriptComponent to.

Type Parameters

T

The space of ScriptComponent to add.

AddScriptComponent<T>(ManagedEntity, Entity)

public void AddScriptComponent<T>(ManagedEntity managedEntity, Entity entity) where T : ScriptComponent, new()

Parameters

managedEntity ManagedEntity
entity Entity

Type Parameters

T

CreateEntities(int)

Create multiple entities with no components.

public void CreateEntities(int count)

Parameters

count int

The number of entities to create.

CreateEntities(int, ComponentSet)

Create multiple entities with specified components.

public void CreateEntities(int count, ComponentSet set)

Parameters

count int

The number of entities to create.

set ComponentSet

A 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

entities Span<Entity>

The span to store the created entities.

CreateEntities(Span<Entity>, ComponentSet)

Create multiple entities with specified components.

public void CreateEntities(Span<Entity> entities, ComponentSet set)

Parameters

entities Span<Entity>

The span to store the created entities.

set ComponentSet

A 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

set ComponentSet

A 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

entity Entity

The 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

componentID Identifier<IComponent>

The component space ID of the singleton.

pComponent void*

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

component T

The component data.

Returns

Error

The result status of the operation.

Type Parameters

T

The component space.

DestroyEntities(ReadOnlySpan<Entity>)

Destroy the specified entities.

public void DestroyEntities(ReadOnlySpan<Entity> entities)

Parameters

entities ReadOnlySpan<Entity>

The entities to destroy.

DestroyEntity(Entity)

Destroy the specified entity.

public Error DestroyEntity(Entity entity)

Parameters

entity Entity

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

managedEntity ManagedEntity

The ManagedEntity to destroy.

DestroyScriptComponent<T>(ManagedEntity)

public bool DestroyScriptComponent<T>(ManagedEntity managedEntity) where T : ScriptComponent

Parameters

managedEntity ManagedEntity

Returns

bool

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

entity Entity

The 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

managedEntity ManagedEntity

The 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

entity Entity

The entity to get the component data for.

componentID Identifier<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

entity Entity

The entity to get the component data for.

Returns

T

Reference to the component data. null ref if not found.

Type Parameters

T

The component space.

GetScriptComponent<T>(ManagedEntity)

public T GetScriptComponent<T>(ManagedEntity managedEntity) where T : ScriptComponent

Parameters

managedEntity ManagedEntity

Returns

T

Type Parameters

T

GetScriptComponents<T>(ManagedEntity)

public List<T> GetScriptComponents<T>(ManagedEntity managedEntity) where T : ScriptComponent

Parameters

managedEntity ManagedEntity

Returns

List<T>

Type Parameters

T

GetSingleton(Identifier<IComponent>)

Get a pointer to the singleton component data.

public void* GetSingleton(Identifier<IComponent> componentID)

Parameters

componentID Identifier<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

T

The component space.

HasComponent(Entity, Identifier<IComponent>)

Check if the specified entity has the specified component.

public bool HasComponent(Entity entity, Identifier<IComponent> componentID)

Parameters

entity Entity

The entity to check.

componentID Identifier<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

entity Entity

The entity to check.

Returns

bool

True if the entity has the component, false otherwise.

Type Parameters

T

The 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

managedEntity ManagedEntity

The ManagedEntity to check.

Returns

bool

True if the ManagedEntity has a ScriptComponent of space T, false

Type Parameters

T

The 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

entity Entity

The entity to remove the component from.

componentID Identifier<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

entity Entity

The entity to remove the component from.

Returns

Error

The result status of the operation.

Type Parameters

T

The 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

entity Entity

The entity to set the component data for.

componentID Identifier<IComponent>

The component space ID to set.

pComponent void*

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

entity Entity

The entity to set the component data for.

component T

The component data.

Returns

Error

Type Parameters

T

The component space.

SetEnabled(Entity, Identifier<IComponent>, bool)

public Error SetEnabled(Entity entity, Identifier<IComponent> componentID, bool enabled)

Parameters

entity Entity
componentID Identifier<IComponent>
enabled bool

Returns

Error

SetEnabled<T>(Entity, bool)

public Error SetEnabled<T>(Entity entity, bool enabled) where T : unmanaged, IEnableableComponent

Parameters

entity Entity
enabled bool

Returns

Error

Type Parameters

T