Documentation

Unity Engine


Unity Engine


EntityManager

The EntityManager manages entities and components in a World.
Read time 6 minutesLast updated 3 days ago

Definition

[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

DebugAn object providing debugging information and operations.
EntityOrderVersionIf this version number increases, it means that a structural change has occurred (Entities created / destroyed or components added / removed)
ExclusiveEntityTransactionDependencyAn optional JobHandle that corresponds to the job currently using an ExclusiveEntityTransaction. This job is completed if this EntityManager's EntityManager.World is destroyed.
GlobalSystemVersionA counter that increments after every system update.
UniversalQueryAn EntityQuery instance that matches all normal components and
UniversalQueryWithSystemsAn EntityQuery instance that matches all normal components and
WorldThe EntityManager.World of this EntityManager.
WorldUnmanagedThe EntityManager.WorldUnmanaged of this EntityManager.

Static Properties

Property

Description

TotalChunkAddressSpaceInBytesThe total reserved address space for all Chunks in all Worlds.

Methods

Method

Description

AddBufferAdds a dynamic buffer component to an entity.
AddChunkComponentDataAdds a chunk component to the specified entity.
AddComponentAdds a component to a set of entities.
AddComponentDataAdds a component to an entity and set the value of that component.
AddSharedComponentAdds a shared component to multiple entities
AddTransformAdds a transform to an entity.
BeginExclusiveEntityTransactionBegins an exclusive entity transaction, which allows you to make structural changes inside a Job.
CanBeginExclusiveEntityTransactionCheck whether or not a new exclusive entity transaction can begin.
CompleteAllTrackedJobsWaits for all tracked jobs to complete.
CompleteDependencyBeforeROCompletes the dependency chain required for this component to have read access. So it completes all write dependencies of the component to allow for reading.
CompleteDependencyBeforeRWCompletes 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.
CopyEntitiesFromInstantiates / 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.
CreateArchetypeCreates an archetype from a set of component types.
CreateEntityCreates an entity with no components.
CreateEntityQueryCreates a EntityQuery from an array of component types.
CreateEntityRemapArrayCreates a remapping array with one element for each entity in the EntityManager.World.
CreateSingletonCreates and supports only a single entity with a given unmanaged component.
CreateSingletonBufferCreates and supports only a single entity with a given unmanaged component buffer.
DestroyEntityDestroys all entities in an array.
DetachChildrenBreak the parent/child links between the target entity and all of its children. Each child entity becomes the root of a new hierarchy.
EndExclusiveEntityTransactionEnds an active ExclusiveEntityTransaction and returns ownership of the EntityManager to the main thread.
EqualsReports whether this EntityManager references the same manager as another object.
ExistsReports whether an Entity object is still valid.
GetAllArchetypesGets all the archetypes.
GetAllChunksGets all the chunks managed by this EntityManager.
GetAllChunksAndMetaChunksGets all the chunks managed by this EntityManager, including the meta chunks (containing chunk components).
GetAllEntitiesGets all the entities managed by this EntityManager.
GetAllUniqueSharedComponentsGets a list of all the unique instances of an unmanaged shared component type.
GetAssignableComponentTypesGets a list of the types of components that can be assigned to the specified component.
GetBufferGets the dynamic buffer of an entity.
GetBufferTypeHandleGets the dynamic type object required to access a chunk buffer containing elements of type T.
GetChunkGets the chunk in which the specified entity is stored.
GetChunkComponentDataGets the value of a chunk component.
GetComponentCountGets the number of component types associated with an entity.
GetComponentDataGets the value of a component for an entity.
GetComponentDataRWGets the value of a component for an entity.
GetComponentOrderVersionGets the version number of the specified component type.
GetComponentTypeHandleGets the dynamic type object required to access a chunk component of type T.
GetComponentTypesGets an entity's component types.
GetDynamicComponentTypeHandleGets the dynamic type object required to access a chunk component of dynamic type acquired from reflection.
GetDynamicSharedComponentTypeHandleGets the dynamic type object required to access a shared component of the given type.
GetEntityTypeHandleGets the dynamic type object required to access the Entity component of a chunk.
GetHashCodeComputes a hash code for this object
GetNameGets the name assigned to an entity.
GetSharedComponentGets a shared component by index.
GetSharedComponentCountGets the number of shared components managed by this EntityManager.
GetSharedComponentDataBoxedRetrieves a shared component value as a managed boxed object.
GetSharedComponentIndexRetrieves the index of the unmanaged shared component for an entity.
GetSharedComponentOrderVersionGets the version number of the specified shared component.
GetSharedComponentTypeHandleGets the dynamic type object required to access a shared component of type T.
GetStorageInfoGets a struct containing information about the archetype in which an entity is stored.
GetTransformRefGets a reference to the transform of an entity.
GetTransformTypeHandleGets a type handle for accessing entity transforms in a chunk.
HasBufferChecks whether an entity has a dynamic buffer of a specific IBufferElementData type.
HasChunkComponentChecks whether the chunk containing an entity has a specific type of component.
HasComponentChecks whether an entity has a specific type of component.
InstantiateClones an entity.
IsComponentEnabledChecks whether a given ComponentType is enabled on the specified Entity.
IsEnabledCheck whether an entire entity has the Disabled tag component.
IsQueryValidCheck if an entity query is still valid
MoveEntitiesFromMoves all entities managed by the specified EntityManager to the EntityManager.World of this EntityManager and fills an array with their Entity objects.
PrepareForDeserializePrepares an empty EntityManager.World to load serialized entities.
RemoveChunkComponentRemoves a chunk component from the specified entity.
RemoveChunkComponentDataRemoves a chunk component from the chunks identified by an EntityQuery.
RemoveComponentRemove a component from a set of entities.
SetArchetypeAdds and removes components of a NativeArray of Entities to match the specified EntityArchetype.
SetChunkComponentDataSets the value of a chunk component.
SetComponentDataSets the value of a component of an entity.
SetComponentEnabledEnable or disable ComponentType on the specified Entity.
SetEnabledAdds or removes the Disabled component to an Entity.
SetNameSets the name of an entity.
SetParentEstablish a new link between a child and parent entity.
SetSharedComponentSets the shared component value on an array of entities
SwapComponentsSwaps 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.EntityManagerDebugProvides information and utility functions for debugging.

Enums

Enum

Description

EntityManager.GetAllEntitiesOptionsOptions include internal entity types such as metaChunkEntity or system entities.