EasyEcs
API reference

World

An ECS world: entities, their components, singletons and the systems that update them.

public sealed class World : IDisposable

An ECS world: entities, their components, singletons and the systems that update them. Worlds are fully isolated; the recommended server layout is one world per thread, which needs no synchronization at all.

Constructors

World

public World(WorldOptions options = null);

A new, empty world configured by options (null: the defaults). O(WorldOptions.InitialEntityCapacity): allocates the entity array and the empty table.

Complexity (API table): O(InitialEntityCapacity)

Fields

ParallelChunkRows

public const int ParallelChunkRows = 16384;

The most rows per chunk of a parallel [ForEach]. Chunks hold about a quarter of each thread's share of the matching rows (at least 1,024): equal chunks finish together, and four per thread even out uneven rows.

Properties

ChangeTick

public ulong ChangeTick { get; }

The current change tick, stamped into tracked components' rows on every write (ITrackChanges).

Complexity (API table): O(1)

Entities

public World.EntityEnumerator Entities { get; }

All alive entities in id order (diagnostics: O(capacity)).

Complexity (API table): O(capacity)

EntityCount

public int EntityCount { get; }

Number of alive entities. O(1).

Complexity (API table): O(1)

Systems

public SystemList Systems { get; }

Systems of every group, each group in execution order (default group first). Allocation-free.

Complexity (API table): O(systems) to walk, Count O(groups)

UpdateCount

public long UpdateCount { get; }

Number of completed World.Update calls (default group).

Complexity (API table): O(1)

Methods

AddSingleton

public ref T AddSingleton<T>() where T : struct, ISingletonComponent;

Add (or reset to default) singleton T and return a ref to it. A reset keeps the storage, so World.SingletonRef handles taken before still reach the singleton. O(1).

Complexity (API table): O(1)

AddSystem

public void AddSystem(EcsSystem system, bool changesFromNow = false);

Attach system to its group (UpdateInGroupAttribute, default otherwise) and call its EcsSystem.OnCreate.

Parameters

  • system: The system, not attached to a world yet.
  • changesFromNow: False (the default): the first run of its [Changed<T>] and [Removed<T>] methods visits every row written or removed since the world began. True: only what is written or removed after this call, as if the system had run just now (EcsSystem.LastRunTick); for a system added to a world that already holds its state (a restart after World.Load, a system switched on later).

Complexity (API table):

  • world.AddSystem<T>(changesFromNow): O(s²), s = systems of its group
  • AddSystem(system, changesFromNow): O(s²), s = systems of its group

AddSystem

public T AddSystem<T>(bool changesFromNow = false) where T : EcsSystem, new();

Create a system, attach it to this world and call its EcsSystem.OnCreate.

Parameters

Complexity (API table):

  • world.AddSystem<T>(changesFromNow): O(s²), s = systems of its group
  • AddSystem(system, changesFromNow): O(s²), s = systems of its group

Any

public bool Any<T1>(in QueryFilter filter = default) where T1 : struct, IComponent;
public bool Any<T1, T2>(in QueryFilter filter = default) where T1 : struct, IComponent where T2 : struct, IComponent;
public bool Any<T1, T2, T3>(in QueryFilter filter = default) where T1 : struct, IComponent where T2 : struct, IComponent where T3 : struct, IComponent;
public bool Any<T1, T2, T3, T4>(in QueryFilter filter = default) where T1 : struct, IComponent where T2 : struct, IComponent where T3 : struct, IComponent where T4 : struct, IComponent;
public bool Any<T1, T2, T3, T4, T5>(in QueryFilter filter = default) where T1 : struct, IComponent where T2 : struct, IComponent where T3 : struct, IComponent where T4 : struct, IComponent where T5 : struct, IComponent;
public bool Any<T1, T2, T3, T4, T5, T6>(in QueryFilter filter = default) 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 Any<T1, T2, T3, T4, T5, T6, T7>(in QueryFilter filter = default) 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 Any<T1, T2, T3, T4, T5, T6, T7, T8>(in QueryFilter filter = default) 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 Any<T1, T2, T3, T4, T5, T6, T7, T8, T9>(in QueryFilter filter = default) 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.

Whether any alive entity has all of T1, T2. O(matching archetypes), plus O(rows / 64) for tables with rows to test; early exit.

Complexity (API table): O(M + S / 64) worst

Capture

public WorldSnapshot Capture();

Copy the entities, their components and the singletons. O(entities × components + archetypes + singletons). Components and singletons are copied by value: a managed reference inside one is shared, not cloned. Not while a pass iterates.

Complexity (API table):

  • world.Capture(): O(entities × components + tables + singletons)
  • Capture(into): O(entities × components + tables + singletons)

Capture

public WorldSnapshot Capture(WorldSnapshot into);

World.Capture into into (a snapshot of this world, or null for a new one), overwriting it and reusing its arrays: capturing every tick (rollback, replays) allocates nothing once they are large enough. Returns the snapshot.

Complexity (API table):

  • world.Capture(): O(entities × components + tables + singletons)
  • Capture(into): O(entities × components + tables + singletons)

Children

public ValueIndex<ChildOf, EntityId>.Matches Children(EntityId parent);

The children of parent: the entities whose ChildOf points at it. O(1), then O(1) per child; the first call indexes every ChildOf once. Owner thread only.

Complexity (API table): O(1), then O(1) per child

Count

public int Count<T1>(in QueryFilter filter = default) where T1 : struct, IComponent;
public int Count<T1, T2>(in QueryFilter filter = default) where T1 : struct, IComponent where T2 : struct, IComponent;
public int Count<T1, T2, T3>(in QueryFilter filter = default) where T1 : struct, IComponent where T2 : struct, IComponent where T3 : struct, IComponent;
public int Count<T1, T2, T3, T4>(in QueryFilter filter = default) where T1 : struct, IComponent where T2 : struct, IComponent where T3 : struct, IComponent where T4 : struct, IComponent;
public int Count<T1, T2, T3, T4, T5>(in QueryFilter filter = default) where T1 : struct, IComponent where T2 : struct, IComponent where T3 : struct, IComponent where T4 : struct, IComponent where T5 : struct, IComponent;
public int Count<T1, T2, T3, T4, T5, T6>(in QueryFilter filter = default) 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 int Count<T1, T2, T3, T4, T5, T6, T7>(in QueryFilter filter = default) 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 int Count<T1, T2, T3, T4, T5, T6, T7, T8>(in QueryFilter filter = default) 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 int Count<T1, T2, T3, T4, T5, T6, T7, T8, T9>(in QueryFilter filter = default) 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.

Number of alive entities having all of T1, T2. O(matching archetypes), plus O(rows / 64) for tables with rows to test.

Complexity (API table): O(M), + S / 64 for tables whose rows must be tested

CreateEntities

public void CreateEntities<T1>(Span<Entity> entities, in T1 c1) where T1 : struct, IComponent;
public void CreateEntities<T1, T2>(Span<Entity> entities, in T1 c1, in T2 c2) where T1 : struct, IComponent where T2 : struct, IComponent;
public void CreateEntities<T1, T2, T3>(Span<Entity> entities, in T1 c1, in T2 c2, in T3 c3) where T1 : struct, IComponent where T2 : struct, IComponent where T3 : struct, IComponent;
public void CreateEntities<T1, T2, T3, T4>(Span<Entity> entities, 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 void CreateEntities<T1, T2, T3, T4, T5>(Span<Entity> entities, 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 void CreateEntities<T1, T2, T3, T4, T5, T6>(Span<Entity> entities, 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 void CreateEntities<T1, T2, T3, T4, T5, T6, T7>(Span<Entity> entities, 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 void CreateEntities<T1, T2, T3, T4, T5, T6, T7, T8>(Span<Entity> entities, 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 void CreateEntities<T1, T2, T3, T4, T5, T6, T7, T8, T9>(Span<Entity> entities, 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.

Create entities.Length entities with 2 components (the same values for each), placed directly in their final archetype, and write their handles to entities. One pass through the structural gate and at most one table growth: O(count × 2). Owner thread only (see docs/content/guide/threading.md).

Complexity (API table): O(count × n) amortized

CreateEntity

public Entity CreateEntity();

Create an entity without components. O(1) amortized. Owner thread only (see docs/content/guide/threading.md).

Complexity (API table):

  • world.CreateEntity(): O(1) amortized
  • world.CreateEntity(in T1 … in Tn): O(n) amortized

CreateEntity

public Entity CreateEntity<T1>(in T1 c1) where T1 : struct, IComponent;
public Entity CreateEntity<T1, T2>(in T1 c1, in T2 c2) where T1 : struct, IComponent where T2 : struct, IComponent;
public Entity CreateEntity<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 CreateEntity<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 CreateEntity<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 CreateEntity<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 CreateEntity<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 CreateEntity<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 CreateEntity<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.

Create an entity with 2 components placed directly in its final archetype (no intermediate moves). O(2) amortized. Owner thread only (see docs/content/guide/threading.md).

Complexity (API table):

  • world.CreateEntity(): O(1) amortized
  • world.CreateEntity(in T1 … in Tn): O(n) amortized

Descendants

public World.Subtree Descendants(EntityId root);

The descendants of root, depth first, each before its own children: its children, their children, and so on (root itself is not one). What a save of a subtree collects: ids.Add(root.Id); foreach (var e in world.Descendants(root.Id)) ids.Add(e.Id);. O(1) per entity; the first walk indexes every ChildOf once. Allocates nothing once warm (the walk's stack is kept by the world). An entity destroyed during the walk is skipped. Owner thread only.

Complexity (API table): O(1) per entity of the subtree

Describe

public TableInfo[] Describe();

The world's tables, for diagnostics (an admin endpoint, a dashboard): what each holds, how full it is and what it costs. Cold: allocates the result; any thread (a table being changed at the same time may be read half-way).

Complexity (API table): O(tables + columns)

DestroyEntities

public int DestroyEntities<T1>(in QueryFilter filter = default) where T1 : struct, IComponent;
public int DestroyEntities<T1, T2>(in QueryFilter filter = default) where T1 : struct, IComponent where T2 : struct, IComponent;
public int DestroyEntities<T1, T2, T3>(in QueryFilter filter = default) where T1 : struct, IComponent where T2 : struct, IComponent where T3 : struct, IComponent;
public int DestroyEntities<T1, T2, T3, T4>(in QueryFilter filter = default) where T1 : struct, IComponent where T2 : struct, IComponent where T3 : struct, IComponent where T4 : struct, IComponent;
public int DestroyEntities<T1, T2, T3, T4, T5>(in QueryFilter filter = default) where T1 : struct, IComponent where T2 : struct, IComponent where T3 : struct, IComponent where T4 : struct, IComponent where T5 : struct, IComponent;
public int DestroyEntities<T1, T2, T3, T4, T5, T6>(in QueryFilter filter = default) 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 int DestroyEntities<T1, T2, T3, T4, T5, T6, T7>(in QueryFilter filter = default) 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 int DestroyEntities<T1, T2, T3, T4, T5, T6, T7, T8>(in QueryFilter filter = default) 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 int DestroyEntities<T1, T2, T3, T4, T5, T6, T7, T8, T9>(in QueryFilter filter = default) 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.

Destroy every alive entity having all of T1, T2 (and matching filter) and return how many. One pass through the structural gate: O(matching archetypes + rows). Owner thread only (see docs/content/guide/threading.md).

Complexity (API table): O(M + S)

DisableAll

public int DisableAll<T>(in QueryFilter filter = default) where T : struct, IComponent;

Entity.Disable on every alive entity having T and matching filter: each keeps its value and gets Disabled. Returns how many. O(matching tables + rows); a table's rows move once, to the table with the tag. Owner thread only.

Complexity (API table): O(M + S)

Dispose

public void Dispose();

Destroy all systems (OnDestroy in reverse order), then release all storage.

Complexity (API table): O(systems + entities + tables)

EnableAll

public int EnableAll<T>(in QueryFilter filter = default) where T : struct, IComponent;

Entity.Enable on every alive entity with T disabled and matching filter: each gets its kept value back (a write of a tracked component; indexes follow). Returns how many. O(matching tables + rows). Owner thread only.

Complexity (API table): O(M + S)

EnsureCapacity

public void EnsureCapacity(Prefab prefab, int count);

Pre-size the table prefab's instances go to, and the entity storage, so the next count World.Instantiate calls never grow them: a wave of spawns pays its growth before the tick. Instances whose groups put them in another table (World.GroupBy) grow that one. For a prefab with members, every member's table. O(components) plus one growth. Owner thread only.

Complexity (API table):

  • world.EnsureCapacity<T1..Tn>(count): O(n), plus one growth
  • world.EnsureCapacity(prefab, count): O(c), plus one growth

EnsureCapacity

public void EnsureCapacity<T1>(int count) where T1 : struct, IComponent;
public void EnsureCapacity<T1, T2>(int count) where T1 : struct, IComponent where T2 : struct, IComponent;
public void EnsureCapacity<T1, T2, T3>(int count) where T1 : struct, IComponent where T2 : struct, IComponent where T3 : struct, IComponent;
public void EnsureCapacity<T1, T2, T3, T4>(int count) where T1 : struct, IComponent where T2 : struct, IComponent where T3 : struct, IComponent where T4 : struct, IComponent;
public void EnsureCapacity<T1, T2, T3, T4, T5>(int count) where T1 : struct, IComponent where T2 : struct, IComponent where T3 : struct, IComponent where T4 : struct, IComponent where T5 : struct, IComponent;
public void EnsureCapacity<T1, T2, T3, T4, T5, T6>(int count) 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 void EnsureCapacity<T1, T2, T3, T4, T5, T6, T7>(int count) 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 void EnsureCapacity<T1, T2, T3, T4, T5, T6, T7, T8>(int count) 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 void EnsureCapacity<T1, T2, T3, T4, T5, T6, T7, T8, T9>(int count) 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.

Pre-size the table of entities with exactly T1, T2 and the entity storage, so the next count CreateEntity / CreateEntities calls with these components never grow them: a start-up or a wave of spawns pays its growth once, before the loop. Entities whose groups put them in another table (World.GroupBy) grow that one; components added later move entities to other tables, which grow on their own. O(2) plus one growth. Owner thread only (see docs/content/guide/threading.md).

Complexity (API table):

  • world.EnsureCapacity<T1..Tn>(count): O(n), plus one growth
  • world.EnsureCapacity(prefab, count): O(c), plus one growth

EnsureEntityCapacity

public void EnsureEntityCapacity(int capacity);

Pre-size entity storage so creating up to capacity entities never grows it.

Complexity (API table): O(capacity)

ForEach

public void ForEach<T1, TJob>(ref TJob job, in QueryFilter filter = default) where T1 : struct, IComponent where TJob : struct, IForEach<T1>, allows ref struct;
public void ForEach<T1, T2, TJob>(ref TJob job, in QueryFilter filter = default) where T1 : struct, IComponent where T2 : struct, IComponent where TJob : struct, IForEach<T1, T2>, allows ref struct;
public void ForEach<T1, T2, T3, TJob>(ref TJob job, in QueryFilter filter = default) where T1 : struct, IComponent where T2 : struct, IComponent where T3 : struct, IComponent where TJob : struct, IForEach<T1, T2, T3>, allows ref struct;
public void ForEach<T1, T2, T3, T4, TJob>(ref TJob job, in QueryFilter filter = default) where T1 : struct, IComponent where T2 : struct, IComponent where T3 : struct, IComponent where T4 : struct, IComponent where TJob : struct, IForEach<T1, T2, T3, T4>, allows ref struct;
public void ForEach<T1, T2, T3, T4, T5, TJob>(ref TJob job, in QueryFilter filter = default) where T1 : struct, IComponent where T2 : struct, IComponent where T3 : struct, IComponent where T4 : struct, IComponent where T5 : struct, IComponent where TJob : struct, IForEach<T1, T2, T3, T4, T5>, allows ref struct;
public void ForEach<T1, T2, T3, T4, T5, T6, TJob>(ref TJob job, in QueryFilter filter = default) 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, IForEach<T1, T2, T3, T4, T5, T6>, allows ref struct;
public void ForEach<T1, T2, T3, T4, T5, T6, T7, TJob>(ref TJob job, in QueryFilter filter = default) 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, IForEach<T1, T2, T3, T4, T5, T6, T7>, allows ref struct;
public void ForEach<T1, T2, T3, T4, T5, T6, T7, T8, TJob>(ref TJob job, in QueryFilter filter = default) 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, IForEach<T1, T2, T3, T4, T5, T6, T7, T8>, allows ref struct;
public void ForEach<T1, T2, T3, T4, T5, T6, T7, T8, T9, TJob>(ref TJob job, in QueryFilter filter = default) 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, IForEach<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 with the components for every entity having all of T1, T2 (and matching filter). The fastest iteration: walks each matching archetype's columns front to back, O(matching archetypes + rows), allocation-free. Structural changes inside the job are allowed and take effect immediately: an entity is visited at most once (entities that enter a matching archetype during the pass are not visited, entities that leave before their turn are skipped), and when the job changes the archetype of the entity it visits, its writes through the refs are carried over to the entity's new row (IForEach.Writes). A job implementing INoStructuralChanges skips that bookkeeping.

Complexity (API table): O(M + S)

ForEachBatch

public void ForEachBatch<T1, TJob>(ref TJob job, in QueryFilter filter = default) where T1 : struct, IComponent where TJob : struct, IForEachBatch<T1>, allows ref struct;
public void ForEachBatch<T1, T2, TJob>(ref TJob job, in QueryFilter filter = default) where T1 : struct, IComponent where T2 : struct, IComponent where TJob : struct, IForEachBatch<T1, T2>, allows ref struct;
public void ForEachBatch<T1, T2, T3, TJob>(ref TJob job, in QueryFilter filter = default) where T1 : struct, IComponent where T2 : struct, IComponent where T3 : struct, IComponent where TJob : struct, IForEachBatch<T1, T2, T3>, allows ref struct;
public void ForEachBatch<T1, T2, T3, T4, TJob>(ref TJob job, in QueryFilter filter = default) where T1 : struct, IComponent where T2 : struct, IComponent where T3 : struct, IComponent where T4 : struct, IComponent where TJob : struct, IForEachBatch<T1, T2, T3, T4>, allows ref struct;
public void ForEachBatch<T1, T2, T3, T4, T5, TJob>(ref TJob job, in QueryFilter filter = default) where T1 : struct, IComponent where T2 : struct, IComponent where T3 : struct, IComponent where T4 : struct, IComponent where T5 : struct, IComponent where TJob : struct, IForEachBatch<T1, T2, T3, T4, T5>, allows ref struct;
public void ForEachBatch<T1, T2, T3, T4, T5, T6, TJob>(ref TJob job, in QueryFilter filter = default) 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, IForEachBatch<T1, T2, T3, T4, T5, T6>, allows ref struct;
public void ForEachBatch<T1, T2, T3, T4, T5, T6, T7, TJob>(ref TJob job, in QueryFilter filter = default) 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, IForEachBatch<T1, T2, T3, T4, T5, T6, T7>, allows ref struct;
public void ForEachBatch<T1, T2, T3, T4, T5, T6, T7, T8, TJob>(ref TJob job, in QueryFilter filter = default) 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, IForEachBatch<T1, T2, T3, T4, T5, T6, T7, T8>, allows ref struct;
public void ForEachBatch<T1, T2, T3, T4, T5, T6, T7, T8, T9, TJob>(ref TJob job, in QueryFilter filter = default) 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, IForEachBatch<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 over every entity having all of T1, T2 (and matching filter), one run of consecutive rows at a time: a dense archetype is a single call. Allocation-free. The job sees spans into the tables, so structural changes throw while it runs (InvalidOperationException).

Complexity (API table): O(M + S / 64 + runs)

ForEachEntity

public void ForEachEntity<T1, TJob>(ref TJob job, in QueryFilter filter = default) where T1 : struct, IComponent where TJob : struct, IForEachEntity<T1>, allows ref struct;
public void ForEachEntity<T1, T2, TJob>(ref TJob job, in QueryFilter filter = default) where T1 : struct, IComponent where T2 : struct, IComponent where TJob : struct, IForEachEntity<T1, T2>, allows ref struct;
public void ForEachEntity<T1, T2, T3, TJob>(ref TJob job, in QueryFilter filter = default) where T1 : struct, IComponent where T2 : struct, IComponent where T3 : struct, IComponent where TJob : struct, IForEachEntity<T1, T2, T3>, allows ref struct;
public void ForEachEntity<T1, T2, T3, T4, TJob>(ref TJob job, in QueryFilter filter = default) 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 void ForEachEntity<T1, T2, T3, T4, T5, TJob>(ref TJob job, in QueryFilter filter = default) 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 void ForEachEntity<T1, T2, T3, T4, T5, T6, TJob>(ref TJob job, in QueryFilter filter = default) 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 void ForEachEntity<T1, T2, T3, T4, T5, T6, T7, TJob>(ref TJob job, in QueryFilter filter = default) 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 void ForEachEntity<T1, T2, T3, T4, T5, T6, T7, T8, TJob>(ref TJob job, in QueryFilter filter = default) 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 void ForEachEntity<T1, T2, T3, T4, T5, T6, T7, T8, T9, TJob>(ref TJob job, in QueryFilter filter = default) 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 with the entity handle for every entity having all of T1, T2 (and matching filter). The fastest iteration: walks each matching archetype's columns front to back, O(matching archetypes + rows), allocation-free. Structural changes inside the job are allowed and take effect immediately: an entity is visited at most once (entities that enter a matching archetype during the pass are not visited, entities that leave before their turn are skipped), and when the job changes the archetype of the entity it visits, its writes through the refs are carried over to the entity's new row (IForEachEntity.Writes). A job implementing INoStructuralChanges skips that bookkeeping.

Complexity (API table): O(M + S)

ForEachEntityParallel

public void ForEachEntityParallel<T1, TJob>(ref TJob job, in QueryFilter filter = default) where T1 : struct, IComponent where TJob : struct, IForEachEntity<T1>, INoStructuralChanges;
public void ForEachEntityParallel<T1, T2, TJob>(ref TJob job, in QueryFilter filter = default) where T1 : struct, IComponent where T2 : struct, IComponent where TJob : struct, IForEachEntity<T1, T2>, INoStructuralChanges;
public void ForEachEntityParallel<T1, T2, T3, TJob>(ref TJob job, in QueryFilter filter = default) where T1 : struct, IComponent where T2 : struct, IComponent where T3 : struct, IComponent where TJob : struct, IForEachEntity<T1, T2, T3>, INoStructuralChanges;
public void ForEachEntityParallel<T1, T2, T3, T4, TJob>(ref TJob job, in QueryFilter filter = default) where T1 : struct, IComponent where T2 : struct, IComponent where T3 : struct, IComponent where T4 : struct, IComponent where TJob : struct, IForEachEntity<T1, T2, T3, T4>, INoStructuralChanges;
public void ForEachEntityParallel<T1, T2, T3, T4, T5, TJob>(ref TJob job, in QueryFilter filter = default) 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>, INoStructuralChanges;
public void ForEachEntityParallel<T1, T2, T3, T4, T5, T6, TJob>(ref TJob job, in QueryFilter filter = default) 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>, INoStructuralChanges;
public void ForEachEntityParallel<T1, T2, T3, T4, T5, T6, T7, TJob>(ref TJob job, in QueryFilter filter = default) 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>, INoStructuralChanges;
public void ForEachEntityParallel<T1, T2, T3, T4, T5, T6, T7, T8, TJob>(ref TJob job, in QueryFilter filter = default) 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>, INoStructuralChanges;
public void ForEachEntityParallel<T1, T2, T3, T4, T5, T6, T7, T8, T9, TJob>(ref TJob job, in QueryFilter filter = default) 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>, INoStructuralChanges;

One overload per number of components, 1 to 9 (generated from one template); this is the text of the two-component one.

World.ForEachEntity on several threads: the matching rows are cut into chunks (about four per thread, a multiple of 64 rows, at most World.ParallelChunkRows) that the calling thread and up to WorldOptions.MaxDegreeOfParallelism - 1 thread-pool threads run at the same time, each with its own copy of job (state a job keeps in its fields is not merged back). The job must not change structure or write anything that another row's run reads (a singleton, another entity); nothing else may change the world during the call. Fewer than two chunks of rows, or a runner already busy, run on the calling thread. Allocation-free after the first call per job type.

Complexity (API table): O(M + S), divided over up to MaxDegreeOfParallelism threads

ForEachParallel

public void ForEachParallel<T1, TJob>(ref TJob job, in QueryFilter filter = default) where T1 : struct, IComponent where TJob : struct, IForEach<T1>, INoStructuralChanges;
public void ForEachParallel<T1, T2, TJob>(ref TJob job, in QueryFilter filter = default) where T1 : struct, IComponent where T2 : struct, IComponent where TJob : struct, IForEach<T1, T2>, INoStructuralChanges;
public void ForEachParallel<T1, T2, T3, TJob>(ref TJob job, in QueryFilter filter = default) where T1 : struct, IComponent where T2 : struct, IComponent where T3 : struct, IComponent where TJob : struct, IForEach<T1, T2, T3>, INoStructuralChanges;
public void ForEachParallel<T1, T2, T3, T4, TJob>(ref TJob job, in QueryFilter filter = default) where T1 : struct, IComponent where T2 : struct, IComponent where T3 : struct, IComponent where T4 : struct, IComponent where TJob : struct, IForEach<T1, T2, T3, T4>, INoStructuralChanges;
public void ForEachParallel<T1, T2, T3, T4, T5, TJob>(ref TJob job, in QueryFilter filter = default) where T1 : struct, IComponent where T2 : struct, IComponent where T3 : struct, IComponent where T4 : struct, IComponent where T5 : struct, IComponent where TJob : struct, IForEach<T1, T2, T3, T4, T5>, INoStructuralChanges;
public void ForEachParallel<T1, T2, T3, T4, T5, T6, TJob>(ref TJob job, in QueryFilter filter = default) 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, IForEach<T1, T2, T3, T4, T5, T6>, INoStructuralChanges;
public void ForEachParallel<T1, T2, T3, T4, T5, T6, T7, TJob>(ref TJob job, in QueryFilter filter = default) 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, IForEach<T1, T2, T3, T4, T5, T6, T7>, INoStructuralChanges;
public void ForEachParallel<T1, T2, T3, T4, T5, T6, T7, T8, TJob>(ref TJob job, in QueryFilter filter = default) 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, IForEach<T1, T2, T3, T4, T5, T6, T7, T8>, INoStructuralChanges;
public void ForEachParallel<T1, T2, T3, T4, T5, T6, T7, T8, T9, TJob>(ref TJob job, in QueryFilter filter = default) 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, IForEach<T1, T2, T3, T4, T5, T6, T7, T8, T9>, INoStructuralChanges;

One overload per number of components, 1 to 9 (generated from one template); this is the text of the two-component one.

World.ForEach on several threads: the matching rows are cut into chunks (about four per thread, a multiple of 64 rows, at most World.ParallelChunkRows) that the calling thread and up to WorldOptions.MaxDegreeOfParallelism - 1 thread-pool threads run at the same time, each with its own copy of job (state a job keeps in its fields is not merged back). The job must not change structure or write anything that another row's run reads (a singleton, another entity); nothing else may change the world during the call. Fewer than two chunks of rows, or a runner already busy, run on the calling thread. Allocation-free after the first call per job type.

Complexity (API table): O(M + S), divided over up to MaxDegreeOfParallelism threads

GetEntity

public Entity GetEntity(EntityId id);

The handle of entity id; throws if that incarnation is not alive. O(1).

Complexity (API table): O(1)

GetOrAddSingleton

public ref T GetOrAddSingleton<T>() where T : struct, ISingletonComponent;

Ref to singleton T, adding it (default) first if missing. O(1).

Complexity (API table): O(1)

GetSingleton

public ref T GetSingleton<T>() where T : struct, ISingletonComponent;

Ref to singleton T; throws if it was not added. O(1).

Complexity (API table): O(1)

GetSystem

public T GetSystem<T>() where T : EcsSystem;

Get the system of type T, or null.

Complexity (API table): O(systems)

GroupBy

public void GroupBy<T>() where T : struct, IComponent, IGroup;

Split this world's tables by T's IGroup.Group: entities of one group share tables, so QueryFilter.InGroup walks only that group's rows, contiguous in memory. Setting a new value moves the entity to its group's tables (one row copy). Existing entities move now: call it at setup. O(entities with T) once; idempotent. Owner thread only, not during a pass.

Complexity (API table): O(entities with T), once

HasSingleton

public bool HasSingleton<T>() where T : struct, ISingletonComponent;

Whether singleton T exists. O(1).

Complexity (API table): O(1)

Index

public ValueIndex<T, TKey> Index<T, TKey>() where T : struct, IComponent, IIndexed<TKey> where TKey : IEquatable<TKey>;

The value index of T: find entities by T's key, or by the entity a relation component points at. Created on the first call (cold), O(1) after; keep it in a local or field. Throws InvalidOperationException when T is already indexed by another key type.

Complexity (API table): O(1); the first call creates it

Instantiate

public Entity Instantiate(Prefab prefab);

Create an entity with a copy of every component of prefab. Values are copied as they are: a DynamicBuffer gets a list of its own, indexes learn the new entity, tracked components count as written now. O(components): one row copy, no table search after the first instance. A prefab with members creates them all and returns the entity of the one passed (O(members × components)). Owner thread only (see docs/content/guide/threading.md).

Complexity (API table):

  • world.Instantiate(prefab): O(c)
  • world.Instantiate(prefab, Span<Entity> entities): O(count × c)

Instantiate

public void Instantiate(Prefab prefab, Span<Entity> entities);

World.Instantiate for entities.Length copies of prefab, whose handles are written to entities: one pass through the structural gate and at most one table growth. O(count × components). Owner thread only.

Complexity (API table):

  • world.Instantiate(prefab): O(c)
  • world.Instantiate(prefab, Span<Entity> entities): O(count × c)

IsAlive

public bool IsAlive(EntityId id);

Whether entity id (that incarnation) is alive. O(1).

Complexity (API table): O(1)

Load

public void Load(ReadOnlySpan<byte> input, bool markWritten = true);

Replace this world's entities, components and singletons with those World.Save wrote (in this process or another). Entities keep their ids and versions, so EntityIds stored in components still point at the same entities, and handles made before the save work again. Components and singletons this process has no type for are skipped (their slices); a type is found by its type id when the process used it or the generator registered it (every component and singleton of a compilation using EasyEcs). Indexes rebuild; groups follow this world's World.GroupBy. O(entities × components). Not while a pass iterates.

Parameters

  • input: The bytes of the save.
  • markWritten: True (the default): every loaded row counts as written now, so [Changed<T>] systems and Changed<T>(since) queries see it. False: the loaded components have no change tick, as if never written, and no row counts as removed; a system added after the load skips them on its first run too (its [Changed<T>] looks at ticks from 1). For a restart that resumes a world saved by another process, whose records already hold the loaded values.

Exceptions

  • InvalidDataException: The bytes are not a save or are damaged, or a component's fields changed since the save (an unmanaged one's size or layout, a managed one's Nino layout). The world is then left as it was.

Complexity (API table): O(entities × components)

LoadEntities

public int LoadEntities(ReadOnlySpan<byte> input, Span<Entity> entities = default);

Create the entities SaveEntities wrote (in this process or another), with new ids, and write their handles in save order into entities (as many as fit); returns how many were created. EntityId fields of their components and buffer elements that named an entity of the group name its new entity, every other one is EntityId.Null (the generator tells the world where those fields are; ids inside collections are not rewritten). A ChildOf whose parent stayed behind is removed: the entity is a root here. Indexes and groups learn the entities; tracked components count as written. O(entities × components). Not while a pass iterates.

Exceptions

  • InvalidDataException: The bytes are not a save.

Complexity (API table): O(entities × components)

LoadEntitiesInto

public int LoadEntitiesInto(ReadOnlySpan<byte> input, ReadOnlySpan<Entity> into, bool markWritten = true);

Put the components World.SaveEntities wrote onto entities that exist already (an actor whose entity was made before its record arrived): the components of the i-th saved entity are set on into[i], added or replacing the values it has, each entity moving table at most once; components the save does not hold stay as they are. Indexes, groups and change ticks follow as with Set (every loaded component counts as written); a disabled component arrives disabled with its value. EntityId fields that named an entity of the group name the entity of into it became, every other one is EntityId.Null, and a ChildOf whose parent stayed behind is not set. Returns how many entities were loaded. O(entities × components). Not while a pass iterates.

With markWritten false, the loaded components do not count as written: each one the save holds has no change tick afterwards, also when it replaces a value written before (a default from a prefab), so [Changed<T>] systems and Since filters do not visit the entity for the load (an actor restored from storage holds what storage has, and "save what changed" saves nothing of it until code writes it). Components the save does not hold keep their ticks.

Exceptions

  • ArgumentException: into does not hold one living entity of this world per saved entity.
  • InvalidDataException: The bytes are not a save.

Complexity (API table): O(entities × components)

MoveEntities

public int MoveEntities(World target, ReadOnlySpan<EntityId> entities, Span<Entity> moved = default);

Move entities (stale ids and repeats are skipped) into target, another world of this thread: the target gets new entities with their components, as World.LoadEntities makes them from a save of the group, without encoding it; then they are destroyed here (their children with them, so move a hierarchy together; cleanup components stay behind for their systems). The new handles are written in order into moved (as many as fit, Entity default for a skipped id); returns how many moved. O(entities × components). Owner thread of both worlds; not while a pass iterates in either.

Complexity (API table): O(entities × components)

Query

public QueryEnumerator<T1> Query<T1>(in QueryFilter filter = default) where T1 : struct, IComponent;
public QueryEnumerator<T1, T2> Query<T1, T2>(in QueryFilter filter = default) where T1 : struct, IComponent where T2 : struct, IComponent;
public QueryEnumerator<T1, T2, T3> Query<T1, T2, T3>(in QueryFilter filter = default) where T1 : struct, IComponent where T2 : struct, IComponent where T3 : struct, IComponent;
public QueryEnumerator<T1, T2, T3, T4> Query<T1, T2, T3, T4>(in QueryFilter filter = default) where T1 : struct, IComponent where T2 : struct, IComponent where T3 : struct, IComponent where T4 : struct, IComponent;
public QueryEnumerator<T1, T2, T3, T4, T5> Query<T1, T2, T3, T4, T5>(in QueryFilter filter = default) where T1 : struct, IComponent where T2 : struct, IComponent where T3 : struct, IComponent where T4 : struct, IComponent where T5 : struct, IComponent;
public QueryEnumerator<T1, T2, T3, T4, T5, T6> Query<T1, T2, T3, T4, T5, T6>(in QueryFilter filter = default) 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 QueryEnumerator<T1, T2, T3, T4, T5, T6, T7> Query<T1, T2, T3, T4, T5, T6, T7>(in QueryFilter filter = default) 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 QueryEnumerator<T1, T2, T3, T4, T5, T6, T7, T8> Query<T1, T2, T3, T4, T5, T6, T7, T8>(in QueryFilter filter = default) 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 QueryEnumerator<T1, T2, T3, T4, T5, T6, T7, T8, T9> Query<T1, T2, T3, T4, T5, T6, T7, T8, T9>(in QueryFilter filter = default) 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.

Enumerate entities having all of T1, T2 (and matching filter). Allocation-free.

Relations

public RelationIndex<T> Relations<T>() where T : struct, IRelation;

The relation index of T: the entities whose DynamicBuffer links to a target. Created on the first call (cold), O(1) after; keep it in a local or field.

Complexity (API table): O(1); the first call creates it

RemoveAll

public int RemoveAll<T>(in QueryFilter filter = default) where T : struct, IComponent;

Remove component T from every alive entity having it and matching filter, as Remove would one by one (rows stay, presence bits clear). Returns how many. O(matching tables + rows). Owner thread only.

Complexity (API table): O(M + S)

RemoveSingleton

public bool RemoveSingleton<T>() where T : struct, ISingletonComponent;

Remove singleton T; false if it was not added. O(1).

Complexity (API table): O(1)

RemoveSystem

public bool RemoveSystem<T>() where T : EcsSystem;

Remove the system of type T (calls its EcsSystem.OnDestroy).

Complexity (API table): O(s²)

RemoveTypes

public void RemoveTypes(Assembly assembly);

Remove from this world everything of the types of assembly: its systems (OnDestroy runs), singletons, indexes and groupings, and its components from every entity (the entities stay, without them). Tables that had such a column are dropped, with every cache that names them, so the world holds no reference to the assembly any more: once every world removed it, its collectible context can unload, and when it does, EasyEcs reuses its component bits.

To reload game logic and keep its data: World.Save, remove the types, unload the old context, load the new version, then World.Load (types are saved by type id, so the new version's components take the values). Owner thread only, not during a pass or an update. O(entities with such components + tables + cached queries); allocates (cold).

Complexity (API table):

  • world.RemoveTypes(assembly): O(entities with such components + tables + cached queries)
  • RemoveTypes(context): O(entities with such components + tables + cached queries)

RemoveTypes

public void RemoveTypes(AssemblyLoadContext context);

World.RemoveTypes for every assembly loaded into context (a plugin and the libraries it brought).

Complexity (API table):

  • world.RemoveTypes(assembly): O(entities with such components + tables + cached queries)
  • RemoveTypes(context): O(entities with such components + tables + cached queries)

Restore

public void Restore(WorldSnapshot snapshot);

Put the world back to snapshot (taken from this world). Handles of entities alive in the snapshot are valid again; every other handle is stale, also handles of entities created after the capture. Archetypes created after the capture stay, empty. Singletons keep their boxes (a World.SingletonRef still works) and get the snapshot's values; singletons added after the capture are removed. O(entities × components + archetypes + singletons). Not while a pass iterates.

Complexity (API table): O(entities × components + tables + singletons)

Save

public void Save(IBufferWriter<byte> output);

Write the entities (ids and versions), their components and the singletons into output, for World.Load. Unmanaged components are their raw rows (a layout change makes old saves unloadable) unless they are [NinoType]s, whose formatter writes them (its format decides what a type may change: fields appended with VersionTolerant, any change of members with Keyed); managed components and singletons need a Nino formatter. Types are recorded by Nino type id: a type renamed with [NinoFormerName] loads its old rows. Allocates nothing once its buffers are large enough. O(entities × components). Not while a pass iterates.

Complexity (API table): O(entities × components)

SaveEntities

public void SaveEntities(IBufferWriter<byte> output, ReadOnlySpan<EntityId> entities);

Write entities (stale ids and repeats are skipped) and their components into output, for World.LoadEntities or World.LoadEntitiesInto: a group of entities that moves to another world (a player and what it owns, to another server). Singletons and the other entities are not written; collect a hierarchy with World.Descendants. Allocates nothing once its buffers are large enough. O(entities given × components). Not while a pass iterates.

Complexity (API table):

  • world.SaveEntities(output, ids): O(entities given × components)
  • world.SaveEntities(output, ids, set): O(entities given × components)

SaveEntities

public void SaveEntities(IBufferWriter<byte> output, ReadOnlySpan<EntityId> entities, in ComponentSet components);

World.SaveEntities of the components in components only (a record of the components that persist, without the runtime ones): the others are not written and need no Nino formatter; a tag is written as present or not, a disabled component with its kept value. Entities without any of them are written too, empty. Allocates nothing once its buffers are large enough. O(entities given × components). Not while a pass iterates.

Complexity (API table):

  • world.SaveEntities(output, ids): O(entities given × components)
  • world.SaveEntities(output, ids, set): O(entities given × components)

SetAll

public int SetAll<T>(in T value, in QueryFilter filter = default) where T : struct, IComponent;

Give every alive entity matching filter component T = value (added, or replaced), as Set would one by one: tracked components count as written, indexes and groups follow. Returns how many entities. O(matching tables + rows); an entity that lacks T moves once. Owner thread only.

Complexity (API table): O(M + S)

SingletonRef

public SingletonRef<T> SingletonRef<T>() where T : struct, ISingletonComponent;

Stable handle to singleton T; throws if it was not added: resolve it once, then read and write SingletonRef.Value without a lookup. Generated [ForEach] jobs resolve singleton parameters through it once per pass, so a system whose singleton was never set fails on its first run. O(1).

Complexity (API table): O(1)

TryGetEntity

public bool TryGetEntity(EntityId id, out Entity entity);

The handle of entity id if that incarnation is alive; false for a destroyed entity (even when its index was reused) and for EntityId.Null. O(1).

Complexity (API table): O(1)

TryGetSingleton

public bool TryGetSingleton<T>(out T value) where T : struct, ISingletonComponent;

Copy of singleton T if present. O(1).

Complexity (API table): O(1)

Update

public void Update();

Run one update of every enabled system of the default group (synchronous). Allocation-free.

Complexity (API table):

  • world.Update(): Σ systems of the group
  • world.Update<TGroup>(): Σ systems of the group

Update

public void Update<TGroup>() where TGroup : struct, ISystemGroup;

Run one update of every enabled system in group TGroup (synchronous, allocation-free). A group with no systems is a no-op.

Complexity (API table):

  • world.Update(): Σ systems of the group
  • world.Update<TGroup>(): Σ systems of the group
Edit on GitHub

Last updated on

How is this guide?

On this page