Struct EntityArchetype
An EntityArchetype is a unique combination of component types. The EntityManager uses the archetype to group all entities that have the same sets of components.
Namespace: Unity.Entities
Syntax
public struct EntityArchetype : IEquatable<EntityArchetype>
Remarks
An entity can change archetype fluidly over its lifespan. For example, when you add or remove components, the archetype of the affected entity changes.
An archetype object is not a container; rather it is an identifier to each unique combination of component types that an application has created at run time, either directly or implicitly.
You can create archetypes directly using CreateArchetype(ComponentType[]). You also implicitly create archetypes whenever you add or remove a component from an entity. An EntityArchetype object is an immutable singleton; creating an archetype with the same set of components, either directly or implicitly, results in the same archetype for a given EntityManager.
The ECS framework uses archetypes to group entities that have the same structure together. The ECS framework stores component data in blocks of memory called chunks. A given chunk stores only entities having the same archetype. You can get the EntityArchetype object for a chunk from its Archetype property.
Properties
ChunkCapacity
The number of entities having this archetype that can fit into a single chunk of memory.
Declaration
public int ChunkCapacity { get; }
Property Value
Type | Description |
---|---|
Int32 | Capacity is determined by the fixed, 16KB size of the memory blocks allocated by the ECS framework and the total storage size of all the component types in the archetype. |
ChunkCount
The current number of chunks storing entities having this archetype.
Declaration
public int ChunkCount { get; }
Property Value
Type | Description |
---|---|
Int32 | The number of chunks. |
Remarks
This value can change whenever structural changes occur. Structural changes include creating or destroying entities, adding components to or removing them from an entity, and changing the value of shared components, all of which alter where entities are stored.
Disabled
Reports whether this EntityArchetype instance contains disabled entities.
Declaration
public bool Disabled { get; }
Property Value
Type | Description |
---|---|
Boolean | True, if the archetype is a disabled archetype. |
Prefab
Reports whether this EntityArchetype instance describes a Prefab.
Declaration
public bool Prefab { get; }
Property Value
Type | Description |
---|---|
Boolean | True, if the archetype is a prefab archetype. |
Valid
Reports whether this EntityArchetype instance references a non-null archetype.
Declaration
public bool Valid { get; }
Property Value
Type | Description |
---|---|
Boolean | True, if the archetype is valid. |
Methods
Equals(Object)
Reports whether this EntityArchetype references the same archetype as another object.
Declaration
public override bool Equals(object compare)
Parameters
Type | Name | Description |
---|---|---|
Object | compare | The object to compare. |
Returns
Type | Description |
---|---|
Boolean | True, if the compare parameter is a EntityArchetype instance that points to the same archetype. |
Overrides
Equals(EntityArchetype)
Compares archetypes for equality.
Declaration
public bool Equals(EntityArchetype entityArchetype)
Parameters
Type | Name | Description |
---|---|---|
EntityArchetype | entityArchetype | The EntityArchetype to compare. |
Returns
Type | Description |
---|---|
Boolean | Returns true, if both EntityArchetype instances reference the same archetype. |
GetComponentTypes(Allocator)
Gets the types of the components making up this archetype.
Declaration
public NativeArray<ComponentType> GetComponentTypes(Allocator allocator = null)
Parameters
Type | Name | Description |
---|---|---|
Allocator | allocator | The allocation type to use for the returned NativeArray. |
Returns
Type | Description |
---|---|
NativeArray<ComponentType> | A native array containing the ComponentType objects of this archetype. |
Remarks
The set of component types in an archetype cannot change; adding components to an entity or removing components from an entity changes the archetype of that entity (possibly resulting in the creation of a new archetype). The original archetype remains unchanged.
GetHashCode()
Returns the hash of the archetype.
Declaration
public override int GetHashCode()
Returns
Type | Description |
---|---|
Int32 | An integer hash code. |
Overrides
Remarks
Two EntityArchetype instances referencing the same archetype return the same hash.
Operators
Equality(EntityArchetype, EntityArchetype)
Compares the archetypes for equality.
Declaration
public static bool operator ==(EntityArchetype lhs, EntityArchetype rhs)
Parameters
Type | Name | Description |
---|---|---|
EntityArchetype | lhs | A EntityArchetype object. |
EntityArchetype | rhs | Another EntityArchetype object. |
Returns
Type | Description |
---|---|
Boolean | True, if these EntityArchetype instances reference the same archetype. |
Inequality(EntityArchetype, EntityArchetype)
Compares the archetypes for inequality.
Declaration
public static bool operator !=(EntityArchetype lhs, EntityArchetype rhs)
Parameters
Type | Name | Description |
---|---|---|
EntityArchetype | lhs | A EntityArchetype object. |
EntityArchetype | rhs | Another EntityArchetype object. |
Returns
Type | Description |
---|---|
Boolean | True, if these EntityArchetype instances reference different archetypes. |