EntityManager
The EntityManager manages entities and components in a World.
Read time 6 minutesLast updated 3 days ago
Definition
- Type: Struct
- Namespace: Unity.Entities
- Assembly: UnityEngine.EntitiesModule
- Implements: IEquatable<EntityManager>
[BurstCompile]public struct EntityManager : IEquatable<EntityManager>
Remarks
The EntityManager provides an API to create, read, update, and destroy entities.
A EntityManager.World has one EntityManager, which manages all the entities for that World.
Many EntityManager operations result in "structural changes" that change the layout of entities in memory. Before it can perform such operations, the EntityManager must wait for all running Jobs to complete, an event called a "sync point". A sync point both blocks the main thread and prevents the application from taking advantage of all available cores as the running Jobs wind down.
Although you cannot prevent sync points entirely, you should avoid them as much as possible. To this end, the ECS framework provides the EntityCommandBuffer, which allows you to queue structural changes so that they all occur at one time in the frame.
Properties
Property | Description |
|---|---|
| Debug | An object providing debugging information and operations. |
| EntityOrderVersion | If this version number increases, it means that a structural change has occurred (Entities created / destroyed or components added / removed) |
| ExclusiveEntityTransactionDependency | An optional JobHandle that corresponds to the job currently using an ExclusiveEntityTransaction. This job is completed if this EntityManager's EntityManager.World is destroyed. |
| GlobalSystemVersion | A counter that increments after every system update. |
| UniversalQuery | An EntityQuery instance that matches all normal components and |
| UniversalQueryWithSystems | An EntityQuery instance that matches all normal components and |
| World | The EntityManager.World of this EntityManager. |
| WorldUnmanaged | The EntityManager.WorldUnmanaged of this EntityManager. |
Static Properties
Property | Description |
|---|---|
| TotalChunkAddressSpaceInBytes | The total reserved address space for all Chunks in all Worlds. |
Methods
Method | Description |
|---|---|
| AddBuffer | Adds a dynamic buffer component to an entity. |
| AddChunkComponentData | Adds a chunk component to the specified entity. |
| AddComponent | Adds a component to a set of entities. |
| AddComponentData | Adds a component to an entity and set the value of that component. |
| AddSharedComponent | Adds a shared component to multiple entities |
| AddTransform | Adds a transform to an entity. |
| BeginExclusiveEntityTransaction | Begins an exclusive entity transaction, which allows you to make structural changes inside a Job. |
| CanBeginExclusiveEntityTransaction | Check whether or not a new exclusive entity transaction can begin. |
| CompleteAllTrackedJobs | Waits for all tracked jobs to complete. |
| CompleteDependencyBeforeRO | Completes the dependency chain required for this component to have read access. So it completes all write dependencies of the component to allow for reading. |
| CompleteDependencyBeforeRW | Completes the dependency chain required for this component to have read and write access. So it completes all write dependencies of the component to allow for reading, and it completes all read dependencies, so we can write to it. |
| CopyEntitiesFrom | Instantiates / Copies all entities from srcEntityManager and copies them into this EntityManager. Entity references on components that are being cloned to entities inside the srcEntities set are remapped to the instantiated entities. |
| CreateArchetype | Creates an archetype from a set of component types. |
| CreateEntity | Creates an entity with no components. |
| CreateEntityQuery | Creates a EntityQuery from an array of component types. |
| CreateEntityRemapArray | Creates a remapping array with one element for each entity in the EntityManager.World. |
| CreateSingleton | Creates and supports only a single entity with a given unmanaged component. |
| CreateSingletonBuffer | Creates and supports only a single entity with a given unmanaged component buffer. |
| DestroyEntity | Destroys all entities in an array. |
| DetachChildren | Break the parent/child links between the target entity and all of its children. Each child entity becomes the root of a new hierarchy. |
| EndExclusiveEntityTransaction | Ends an active ExclusiveEntityTransaction and returns ownership of the EntityManager to the main thread. |
| Equals | Reports whether this EntityManager references the same manager as another object. |
| Exists | Reports whether an Entity object is still valid. |
| GetAllArchetypes | Gets all the archetypes. |
| GetAllChunks | Gets all the chunks managed by this EntityManager. |
| GetAllChunksAndMetaChunks | Gets all the chunks managed by this EntityManager, including the meta chunks (containing chunk components). |
| GetAllEntities | Gets all the entities managed by this EntityManager. |
| GetAllUniqueSharedComponents | Gets a list of all the unique instances of an unmanaged shared component type. |
| GetAssignableComponentTypes | Gets a list of the types of components that can be assigned to the specified component. |
| GetBuffer | Gets the dynamic buffer of an entity. |
| GetBufferTypeHandle | Gets the dynamic type object required to access a chunk buffer containing elements of type T. |
| GetChunk | Gets the chunk in which the specified entity is stored. |
| GetChunkComponentData | Gets the value of a chunk component. |
| GetComponentCount | Gets the number of component types associated with an entity. |
| GetComponentData | Gets the value of a component for an entity. |
| GetComponentDataRW | Gets the value of a component for an entity. |
| GetComponentOrderVersion | Gets the version number of the specified component type. |
| GetComponentTypeHandle | Gets the dynamic type object required to access a chunk component of type T. |
| GetComponentTypes | Gets an entity's component types. |
| GetDynamicComponentTypeHandle | Gets the dynamic type object required to access a chunk component of dynamic type acquired from reflection. |
| GetDynamicSharedComponentTypeHandle | Gets the dynamic type object required to access a shared component of the given type. |
| GetEntityTypeHandle | Gets the dynamic type object required to access the Entity component of a chunk. |
| GetHashCode | Computes a hash code for this object |
| GetName | Gets the name assigned to an entity. |
| GetSharedComponent | Gets a shared component by index. |
| GetSharedComponentCount | Gets the number of shared components managed by this EntityManager. |
| GetSharedComponentDataBoxed | Retrieves a shared component value as a managed boxed object. |
| GetSharedComponentIndex | Retrieves the index of the unmanaged shared component for an entity. |
| GetSharedComponentOrderVersion | Gets the version number of the specified shared component. |
| GetSharedComponentTypeHandle | Gets the dynamic type object required to access a shared component of type T. |
| GetStorageInfo | Gets a struct containing information about the archetype in which an entity is stored. |
| GetTransformRef | Gets a reference to the transform of an entity. |
| GetTransformTypeHandle | Gets a type handle for accessing entity transforms in a chunk. |
| HasBuffer | Checks whether an entity has a dynamic buffer of a specific IBufferElementData type. |
| HasChunkComponent | Checks whether the chunk containing an entity has a specific type of component. |
| HasComponent | Checks whether an entity has a specific type of component. |
| Instantiate | Clones an entity. |
| IsComponentEnabled | Checks whether a given ComponentType is enabled on the specified Entity. |
| IsEnabled | Check whether an entire entity has the Disabled tag component. |
| IsQueryValid | Check if an entity query is still valid |
| MoveEntitiesFrom | Moves all entities managed by the specified EntityManager to the EntityManager.World of this EntityManager and fills an array with their Entity objects. |
| PrepareForDeserialize | Prepares an empty EntityManager.World to load serialized entities. |
| RemoveChunkComponent | Removes a chunk component from the specified entity. |
| RemoveChunkComponentData | Removes a chunk component from the chunks identified by an EntityQuery. |
| RemoveComponent | Remove a component from a set of entities. |
| SetArchetype | Adds and removes components of a NativeArray of Entities to match the specified EntityArchetype. |
| SetChunkComponentData | Sets the value of a chunk component. |
| SetComponentData | Sets the value of a component of an entity. |
| SetComponentEnabled | Enable or disable ComponentType on the specified Entity. |
| SetEnabled | Adds or removes the Disabled component to an Entity. |
| SetName | Sets the name of an entity. |
| SetParent | Establish a new link between a child and parent entity. |
| SetSharedComponent | Sets the shared component value on an array of entities |
| SwapComponents | Swaps the components of two entities. |
Operators
Operator | Description |
|---|---|
| operator == | Compare two EntityManager objects for equality |
| operator != | Compare two EntityManager objects for inequality |
Structs
Struct | Description |
|---|---|
| EntityManager.EntityManagerDebug | Provides information and utility functions for debugging. |
Enums
Enum | Description |
|---|---|
| EntityManager.GetAllEntitiesOptions | Options include internal entity types such as metaChunkEntity or system entities. |