Entity
Handle to an entity: id + version + world (16 bytes). The Entity struct of EasyEcs, the C# ECS: its members, parameters and complexity.
public readonly struct Entity : IEquatable<Entity>Handle to an entity: id + version + world (16 bytes). Every access validates the version, so a handle to a destroyed entity never touches the entity that reused its id: questions (Entity.IsAlive, Entity.Has, Entity.TryGet, Entity.TryGetRef) answer false, accesses and changes (Entity.Get, Entity.Read, Entity.GetOrAdd, Set, Remove) throw, and Entity.Destroy does nothing. Safe to store and to compare.
Remarks
Refs returned by Entity.Get/Entity.GetOrAdd point into the row of the entity's archetype table: use them immediately and never keep them across a structural change of that entity (it moves the row) or an await.
Fields
Id
public readonly EntityId Id;The entity's identity (index and incarnation): what to store in a component or send elsewhere to refer to it (World.TryGetEntity turns it back into a handle).
Properties
IsAlive
public bool IsAlive { get; }Whether this incarnation is alive. O(1).
Complexity (API table): O(1)
World
public World World { get; }The world owning the entity (null for default).
Methods
AddRelation
public Entity AddRelation<T>(in T relation) where T : struct, IRelation;Link the entity to relation's target: append it to the entity's DynamicBuffer (added first if missing) and to the relation index. Returns the entity. O(1) amortized; structural only when the buffer is added. Throws if the entity is not alive.
Complexity (API table): O(1) amortized
Clone
public Entity Clone();A new entity of the same world with a copy of every component of this one (a DynamicBuffer gets a list of its own, indexes learn the copy, tracked components count as written now); throws if this entity is not alive. To create entities from a template, use a Prefab. O(components). Owner thread only.
Complexity (API table): O(c)
Describe
public ComponentValue[] Describe();Boxed copies of the entity's components, disabled ones marked; none when it is not alive. For diagnostics (the debugger shows the same): cold, allocates. O(components). Owner thread only.
Complexity (API table): O(c)
Destroy
public void Destroy();Destroy the entity; a destroyed handle is ignored. O(components).
Complexity (API table): O(c)
Disable
public bool Disable<T>() where T : struct, IComponent;Disable component T: the entity keeps its value but lacks it (queries, Has, Get) until Entity.Enable, and gets the tag Disabled. Counts as a removal for [Removed<T>]; an indexed component leaves its index. Returns false when the entity lacks T (or has it disabled already); throws if it is not alive. O(1); the first disable in a table moves the row once (to the table with the tag's column). Not for an ICleanupComponent (it must stay to be released) or ChildOf (a parent's destruction must find its children): those throw. Owner thread only.
Complexity (API table): O(1); the first disable in a table moves the row once
Enable
public bool Enable<T>() where T : struct, IComponent;Give back a component disabled by Entity.Disable, with the value it kept (Set would replace it). Counts as a write of a tracked component; an indexed one rejoins its index. Returns false when T is not disabled; throws if the entity is not alive. O(1). Owner thread only.
Complexity (API table): O(1); the first disable in a table moves the row once
Equals
public bool Equals(Entity other);
public override bool Equals(object obj);Whether both handles name the same entity of the same world: id and version. O(1).
Get
public ref T Get<T>() where T : struct, IComponent;Ref to component T; throws if the entity does not have it or is not alive. Counts as a write of a tracked component (ITrackChanges). O(1).
Complexity (API table): O(1)
GetHashCode
public override int GetHashCode();A hash of the id and version. O(1).
GetOrAdd
public ref T GetOrAdd<T>() where T : struct, IComponent;Ref to component T, adding it (default) first if missing. Counts as a write of a tracked component. O(1); when missing, O(1) if the entity's table has a column for it (the row only gets its presence bit back), else O(c) amortized: the row moves to the table with the column (c components copied).
Complexity (API table): O(1); when missing, O(1) if the table has a column for T, else O(c) amortized
Has
public bool Has<T>() where T : struct, IComponent;Whether the entity has component T; false for a destroyed or default handle. O(1).
Complexity (API table):
entity.Has<T>(): O(1)entity.Has<T1..Tn>(): O(n)
Has
public bool Has<T1, T2>() where T1 : struct, IComponent where T2 : struct, IComponent;
public bool Has<T1, T2, T3>() where T1 : struct, IComponent where T2 : struct, IComponent where T3 : struct, IComponent;
public bool Has<T1, T2, T3, T4>() where T1 : struct, IComponent where T2 : struct, IComponent where T3 : struct, IComponent where T4 : struct, IComponent;
public bool Has<T1, T2, T3, T4, T5>() where T1 : struct, IComponent where T2 : struct, IComponent where T3 : struct, IComponent where T4 : struct, IComponent where T5 : struct, IComponent;
public bool Has<T1, T2, T3, T4, T5, T6>() where T1 : struct, IComponent where T2 : struct, IComponent where T3 : struct, IComponent where T4 : struct, IComponent where T5 : struct, IComponent where T6 : struct, IComponent;
public bool Has<T1, T2, T3, T4, T5, T6, T7>() where T1 : struct, IComponent where T2 : struct, IComponent where T3 : struct, IComponent where T4 : struct, IComponent where T5 : struct, IComponent where T6 : struct, IComponent where T7 : struct, IComponent;
public bool Has<T1, T2, T3, T4, T5, T6, T7, T8>() where T1 : struct, IComponent where T2 : struct, IComponent where T3 : struct, IComponent where T4 : struct, IComponent where T5 : struct, IComponent where T6 : struct, IComponent where T7 : struct, IComponent where T8 : struct, IComponent;
public bool Has<T1, T2, T3, T4, T5, T6, T7, T8, T9>() where T1 : struct, IComponent where T2 : struct, IComponent where T3 : struct, IComponent where T4 : struct, IComponent where T5 : struct, IComponent where T6 : struct, IComponent where T7 : struct, IComponent where T8 : struct, IComponent where T9 : struct, IComponent;Whether the entity has all of T1, T2; false for a destroyed or default handle. O(2).
Complexity (API table):
entity.Has<T>(): O(1)entity.Has<T1..Tn>(): O(n)
HasRelation
public bool HasRelation<T>(EntityId target) where T : struct, IRelation;Whether the entity links to target with a T. O(links of the entity).
Complexity (API table): O(L)
IsDisabled
public bool IsDisabled<T>() where T : struct, IComponent;Whether component T is disabled (Entity.Disable): the entity has Disabled. O(1).
Complexity (API table): O(1)
Read
public ref readonly T Read<T>() where T : struct, IComponent;Read-only ref to component T; throws if the entity does not have it or is not alive. Not a write: a tracked component (ITrackChanges) is not stamped. O(1).
Complexity (API table): O(1)
Remove
public Entity Remove<T1>() where T1 : struct, IComponent;
public Entity Remove<T1, T2>() where T1 : struct, IComponent where T2 : struct, IComponent;
public Entity Remove<T1, T2, T3>() where T1 : struct, IComponent where T2 : struct, IComponent where T3 : struct, IComponent;
public Entity Remove<T1, T2, T3, T4>() where T1 : struct, IComponent where T2 : struct, IComponent where T3 : struct, IComponent where T4 : struct, IComponent;
public Entity Remove<T1, T2, T3, T4, T5>() where T1 : struct, IComponent where T2 : struct, IComponent where T3 : struct, IComponent where T4 : struct, IComponent where T5 : struct, IComponent;
public Entity Remove<T1, T2, T3, T4, T5, T6>() where T1 : struct, IComponent where T2 : struct, IComponent where T3 : struct, IComponent where T4 : struct, IComponent where T5 : struct, IComponent where T6 : struct, IComponent;
public Entity Remove<T1, T2, T3, T4, T5, T6, T7>() where T1 : struct, IComponent where T2 : struct, IComponent where T3 : struct, IComponent where T4 : struct, IComponent where T5 : struct, IComponent where T6 : struct, IComponent where T7 : struct, IComponent;
public Entity Remove<T1, T2, T3, T4, T5, T6, T7, T8>() where T1 : struct, IComponent where T2 : struct, IComponent where T3 : struct, IComponent where T4 : struct, IComponent where T5 : struct, IComponent where T6 : struct, IComponent where T7 : struct, IComponent where T8 : struct, IComponent;
public Entity Remove<T1, T2, T3, T4, T5, T6, T7, T8, T9>() where T1 : struct, IComponent where T2 : struct, IComponent where T3 : struct, IComponent where T4 : struct, IComponent where T5 : struct, IComponent where T6 : struct, IComponent where T7 : struct, IComponent where T8 : struct, IComponent where T9 : struct, IComponent;One overload per number of components, 1 to 9 (generated from one template); this is the text of the two-component one.
Remove 2 components; missing components are ignored. The entity keeps its row (no move). Returns the entity for chaining. O(2). Owner thread only (see docs/content/guide/threading.md).
Complexity (API table): O(n)
RemoveRelation
public int RemoveRelation<T>(EntityId target) where T : struct, IRelation;Drop the entity's links of kind T to target (every element with that target). Returns how many went. O(links of the entity). Throws if the entity is not alive.
Complexity (API table): O(L)
Run
public bool Run<T1, TJob>(ref TJob job) where T1 : struct, IComponent where TJob : struct, IForEachEntity<T1>, allows ref struct;
public bool Run<T1, T2, TJob>(ref TJob job) where T1 : struct, IComponent where T2 : struct, IComponent where TJob : struct, IForEachEntity<T1, T2>, allows ref struct;
public bool Run<T1, T2, T3, TJob>(ref TJob job) where T1 : struct, IComponent where T2 : struct, IComponent where T3 : struct, IComponent where TJob : struct, IForEachEntity<T1, T2, T3>, allows ref struct;
public bool Run<T1, T2, T3, T4, TJob>(ref TJob job) where T1 : struct, IComponent where T2 : struct, IComponent where T3 : struct, IComponent where T4 : struct, IComponent where TJob : struct, IForEachEntity<T1, T2, T3, T4>, allows ref struct;
public bool Run<T1, T2, T3, T4, T5, TJob>(ref TJob job) where T1 : struct, IComponent where T2 : struct, IComponent where T3 : struct, IComponent where T4 : struct, IComponent where T5 : struct, IComponent where TJob : struct, IForEachEntity<T1, T2, T3, T4, T5>, allows ref struct;
public bool Run<T1, T2, T3, T4, T5, T6, TJob>(ref TJob job) where T1 : struct, IComponent where T2 : struct, IComponent where T3 : struct, IComponent where T4 : struct, IComponent where T5 : struct, IComponent where T6 : struct, IComponent where TJob : struct, IForEachEntity<T1, T2, T3, T4, T5, T6>, allows ref struct;
public bool Run<T1, T2, T3, T4, T5, T6, T7, TJob>(ref TJob job) where T1 : struct, IComponent where T2 : struct, IComponent where T3 : struct, IComponent where T4 : struct, IComponent where T5 : struct, IComponent where T6 : struct, IComponent where T7 : struct, IComponent where TJob : struct, IForEachEntity<T1, T2, T3, T4, T5, T6, T7>, allows ref struct;
public bool Run<T1, T2, T3, T4, T5, T6, T7, T8, TJob>(ref TJob job) where T1 : struct, IComponent where T2 : struct, IComponent where T3 : struct, IComponent where T4 : struct, IComponent where T5 : struct, IComponent where T6 : struct, IComponent where T7 : struct, IComponent where T8 : struct, IComponent where TJob : struct, IForEachEntity<T1, T2, T3, T4, T5, T6, T7, T8>, allows ref struct;
public bool Run<T1, T2, T3, T4, T5, T6, T7, T8, T9, TJob>(ref TJob job) where T1 : struct, IComponent where T2 : struct, IComponent where T3 : struct, IComponent where T4 : struct, IComponent where T5 : struct, IComponent where T6 : struct, IComponent where T7 : struct, IComponent where T8 : struct, IComponent where T9 : struct, IComponent where TJob : struct, IForEachEntity<T1, T2, T3, T4, T5, T6, T7, T8, T9>, allows ref struct;One overload per number of components, 1 to 9 (generated from one template); this is the text of the two-component one.
Run job on this entity when it has all of T1, T2, with the refs World.ForEachEntity would give it: true when the job ran, false when the entity lacks a component or is not alive. The components the job writes (IForEachEntity.Writes) count as written; a structural change the job makes takes effect at once, and those writes are carried over to the entity's new row (also when the job throws). A job implementing INoStructuralChanges skips that bookkeeping. O(1), allocation-free.
Complexity (API table):
entity.Run<T1..Tn, TJob>(ref job): O(n), plus O(1) per filter componentRun(ref job, filter): O(n), plus O(1) per filter component
Run
public bool Run<T1, TJob>(ref TJob job, in QueryFilter filter) where T1 : struct, IComponent where TJob : struct, IForEachEntity<T1>, allows ref struct;
public bool Run<T1, T2, TJob>(ref TJob job, in QueryFilter filter) where T1 : struct, IComponent where T2 : struct, IComponent where TJob : struct, IForEachEntity<T1, T2>, allows ref struct;
public bool Run<T1, T2, T3, TJob>(ref TJob job, in QueryFilter filter) where T1 : struct, IComponent where T2 : struct, IComponent where T3 : struct, IComponent where TJob : struct, IForEachEntity<T1, T2, T3>, allows ref struct;
public bool Run<T1, T2, T3, T4, TJob>(ref TJob job, in QueryFilter filter) where T1 : struct, IComponent where T2 : struct, IComponent where T3 : struct, IComponent where T4 : struct, IComponent where TJob : struct, IForEachEntity<T1, T2, T3, T4>, allows ref struct;
public bool Run<T1, T2, T3, T4, T5, TJob>(ref TJob job, in QueryFilter filter) where T1 : struct, IComponent where T2 : struct, IComponent where T3 : struct, IComponent where T4 : struct, IComponent where T5 : struct, IComponent where TJob : struct, IForEachEntity<T1, T2, T3, T4, T5>, allows ref struct;
public bool Run<T1, T2, T3, T4, T5, T6, TJob>(ref TJob job, in QueryFilter filter) where T1 : struct, IComponent where T2 : struct, IComponent where T3 : struct, IComponent where T4 : struct, IComponent where T5 : struct, IComponent where T6 : struct, IComponent where TJob : struct, IForEachEntity<T1, T2, T3, T4, T5, T6>, allows ref struct;
public bool Run<T1, T2, T3, T4, T5, T6, T7, TJob>(ref TJob job, in QueryFilter filter) where T1 : struct, IComponent where T2 : struct, IComponent where T3 : struct, IComponent where T4 : struct, IComponent where T5 : struct, IComponent where T6 : struct, IComponent where T7 : struct, IComponent where TJob : struct, IForEachEntity<T1, T2, T3, T4, T5, T6, T7>, allows ref struct;
public bool Run<T1, T2, T3, T4, T5, T6, T7, T8, TJob>(ref TJob job, in QueryFilter filter) where T1 : struct, IComponent where T2 : struct, IComponent where T3 : struct, IComponent where T4 : struct, IComponent where T5 : struct, IComponent where T6 : struct, IComponent where T7 : struct, IComponent where T8 : struct, IComponent where TJob : struct, IForEachEntity<T1, T2, T3, T4, T5, T6, T7, T8>, allows ref struct;
public bool Run<T1, T2, T3, T4, T5, T6, T7, T8, T9, TJob>(ref TJob job, in QueryFilter filter) where T1 : struct, IComponent where T2 : struct, IComponent where T3 : struct, IComponent where T4 : struct, IComponent where T5 : struct, IComponent where T6 : struct, IComponent where T7 : struct, IComponent where T8 : struct, IComponent where T9 : struct, IComponent where TJob : struct, IForEachEntity<T1, T2, T3, T4, T5, T6, T7, T8, T9>, allows ref struct;One overload per number of components, 1 to 9 (generated from one template); this is the text of the two-component one.
Entity.Run when the entity also passes filter, tested as a query tests a row (Without, WithAny, Changed, groups): false, without running the job, when it does not. O(components the filter names).
Complexity (API table):
entity.Run<T1..Tn, TJob>(ref job): O(n), plus O(1) per filter componentRun(ref job, filter): O(n), plus O(1) per filter component
Set
public Entity Set<T1>(in T1 c1) where T1 : struct, IComponent;
public Entity Set<T1, T2>(in T1 c1, in T2 c2) where T1 : struct, IComponent where T2 : struct, IComponent;
public Entity Set<T1, T2, T3>(in T1 c1, in T2 c2, in T3 c3) where T1 : struct, IComponent where T2 : struct, IComponent where T3 : struct, IComponent;
public Entity Set<T1, T2, T3, T4>(in T1 c1, in T2 c2, in T3 c3, in T4 c4) where T1 : struct, IComponent where T2 : struct, IComponent where T3 : struct, IComponent where T4 : struct, IComponent;
public Entity Set<T1, T2, T3, T4, T5>(in T1 c1, in T2 c2, in T3 c3, in T4 c4, in T5 c5) where T1 : struct, IComponent where T2 : struct, IComponent where T3 : struct, IComponent where T4 : struct, IComponent where T5 : struct, IComponent;
public Entity Set<T1, T2, T3, T4, T5, T6>(in T1 c1, in T2 c2, in T3 c3, in T4 c4, in T5 c5, in T6 c6) where T1 : struct, IComponent where T2 : struct, IComponent where T3 : struct, IComponent where T4 : struct, IComponent where T5 : struct, IComponent where T6 : struct, IComponent;
public Entity Set<T1, T2, T3, T4, T5, T6, T7>(in T1 c1, in T2 c2, in T3 c3, in T4 c4, in T5 c5, in T6 c6, in T7 c7) where T1 : struct, IComponent where T2 : struct, IComponent where T3 : struct, IComponent where T4 : struct, IComponent where T5 : struct, IComponent where T6 : struct, IComponent where T7 : struct, IComponent;
public Entity Set<T1, T2, T3, T4, T5, T6, T7, T8>(in T1 c1, in T2 c2, in T3 c3, in T4 c4, in T5 c5, in T6 c6, in T7 c7, in T8 c8) where T1 : struct, IComponent where T2 : struct, IComponent where T3 : struct, IComponent where T4 : struct, IComponent where T5 : struct, IComponent where T6 : struct, IComponent where T7 : struct, IComponent where T8 : struct, IComponent;
public Entity Set<T1, T2, T3, T4, T5, T6, T7, T8, T9>(in T1 c1, in T2 c2, in T3 c3, in T4 c4, in T5 c5, in T6 c6, in T7 c7, in T8 c8, in T9 c9) where T1 : struct, IComponent where T2 : struct, IComponent where T3 : struct, IComponent where T4 : struct, IComponent where T5 : struct, IComponent where T6 : struct, IComponent where T7 : struct, IComponent where T8 : struct, IComponent where T9 : struct, IComponent;One overload per number of components, 1 to 9 (generated from one template); this is the text of the two-component one.
Add or overwrite 2 components with the given values, with at most one row copy. Returns the entity for chaining. O(2) amortized. Owner thread only (see docs/content/guide/threading.md).
Complexity (API table): O(n), or O(c) amortized when it moves
ToString
public override string ToString();Entity 3v1: the id's index and version.
TryGet
public bool TryGet<T>(out T value) where T : struct, IComponent;Copy of component T if the entity has it; false when it does not or is not alive. Not a write. O(1).
Complexity (API table): O(1)
TryGetRef
public ref T TryGetRef<T>(out bool found) where T : struct, IComponent;Ref to component T when the entity has it (found), else a null ref: check found before using it. False when the entity is not alive. Counts as a write of a tracked component when found. O(1).
Complexity (API table): O(1)
Operators
operator !=
public static bool operator !=(Entity left, Entity right);Whether the handles name different entities (or worlds). O(1).
operator ==
public static bool operator ==(Entity left, Entity right);Whether both handles name the same entity of the same world: id and version. O(1).
operator implicit
public static implicit operator EntityId(Entity entity);The handle's Entity.Id: store ids, not handles, in components.
Last updated on
How is this guide?