Bulk changes
Set, remove, disable or enable one component on every entity a filter selects in one pass, for round resets, zone-wide statuses and waves, with 0 B allocated.
A round ends and every fighter is stunned; the stun lifts from everyone; a zone freezes; a wave of monsters spawns and
is later cleared. Written entity by entity, each of these is a loop of structural changes. SetAll, RemoveAll,
DisableAll and EnableAll change one component on every entity a filter selects in one pass through the structural
gate, a whole 64-row word at a time where they can, with the same results as the loop: tracked components count as
written, indexes and groups follow.
When to use it
Use it for
The same change on many entities at once: round resets, a status applied to or lifted from a whole team or zone,
pausing a component everywhere (DisableAll), spawning and clearing waves (CreateEntities, DestroyEntities).
Skip it for
Changes whose value depends on each entity (damage from each unit's armor): that is a [ForEach] system writing
through ref. A handful of entities you already hold: Set on each is as fast.
How to use it
Set and remove on every match
SetAll(value, filter) gives every matching entity the component, added or replaced; RemoveAll<T>(filter) removes
it from every match that has it. Both return how many entities they changed.
public record struct Fighter(int Team) : IComponent;
public record struct Stun(int Ticks) : IComponent;
public static class Rounds
{
public static readonly QueryFilter Fighters = QueryFilter.Create().With<Fighter>();
}var fighters = new Entity[1_000];
world.CreateEntities(fighters, new Fighter(1), new Health(100));
int stunned = world.SetAll(new Stun(3), Rounds.Fighters); // the round ends: everyone is stunned
int lifted = world.RemoveAll<Stun>(); // the stun lifts from everyoneWithout a filter, RemoveAll<T>() takes T from every entity that has it, and SetAll gives it to every alive entity,
so name what to select (With<Fighter>()). Any QueryFilter works, including Without, WithAny, Changed and
InGroup.
Disable and enable on every match
DisableAll<T>(filter) and EnableAll<T>(filter) are Disable<T>() and Enable<T>()
on every match: values are kept and given back.
int paused = world.DisableAll<Health>(Rounds.Fighters); // nobody regenerates during the cutscene
int resumed = world.EnableAll<Health>(); // every kept value comes backSpawn and clear waves
The structural counterparts for whole entities create a wave with one set of values and destroy every match:
public record struct Shot(int Damage) : IComponent;var volley = new Entity[10_000];
world.CreateEntities(volley, new Shot(5), new Position(0, 0)); // one table, rows placed at once
int cleared = world.DestroyEntities<Shot>(); // every shot, in one passworld.Instantiate(prefab, span) spawns a wave from a prefab.
What the bulk calls keep
SetAll | RemoveAll | DisableAll | EnableAll | |
|---|---|---|---|---|
| Change tracking | a write per row | a removal per row (tracked T) | a removal per row | a write per row |
| Indexes | re-indexed | unlinked | unlinked | re-linked |
| Groups | moved to the value's group | |||
On a disabled T | replaced: enabled, with the new value | |||
| Cleanup components | the last one frees a retired entity | refused (throws) |
All four are structural changes of the owner thread: call them between updates, from a system's OnUpdate, or from a
[ForEach] method that takes an Entity or the World (a method that takes neither promises no structural change).
Full example
A round of a fight: 1,000 fighters are stunned and released, their regeneration paused for a cutscene and resumed,
then a volley of shots is spawned and cleared, each with one call. A system heals the fighters that are neither
stunned nor paused. Put the files in a console project that references EasyEcs (dotnet add package EasyEcs) and run
it with dotnet run.
It prints:
stunned 1000: health 100
lifted 1000: health 102
paused 1000: health 102
resumed 1000: health 104
set while paused: health 109, still paused 0
shots cleared: 10000, entities left: 1000The stunned update heals nobody (100), the paused one neither (102 stays 102). SetAll on the paused Regen gives
it back with the new value at once: the next update heals 5, and no Disabled<Regen> is left.
How to use it fast
- Let the column stay. After the first round, the stun's column stays in the fighters' table:
SetAllandRemoveAllthen flip presence bits, 64 rows per word, and no row moves. - Keep the filter in a
static readonlyfield, like any hot filter. - One call instead of a loop. The bulk call enters the structural gate once and works table by table.
A round reset of 100,000 fighters (stun everyone, lift it) and a status disabled and enabled for all of them, in bulk
and entity by entity (BulkBenchmark):
| Case | Mean | vs baseline | Allocated |
|---|---|---|---|
| StunAndLift | 87.9 μs | 1.00× | 0 B |
| StunAndLiftEach | 1.68 ms | 19× | 0 B |
| DisableAndEnable | 22.9 μs | 0.26× | 0 B |
| DisableAndEnableEach | 2.27 ms | 26× | 0 B |
What it costs
- Time: O(matching tables + rows). Rows that already have the column are a presence-bit flip; an entity that lacks the column moves once, to the table that has it.
- Allocation: 0 B once the target tables exist.
SetAllcounts first: a moved row can be visited again in its new table, so the count is taken before the change.
Pitfalls
| Mistake | What happens | Caught by |
|---|---|---|
A bulk call inside a [ForEach] method without Entity or World | A structural change the pass did not plan for | EECS013 |
| A bulk call from another thread | Races with the owner thread | EECS014 |
DisableAll of a cleanup component or ChildOf | InvalidOperationException | At run time |
SetAll with a value that should differ per entity | Every entity gets the same value | Use a [ForEach] system |
Set / Remove entity by entity over a query | The same result, one structural change per entity | EECS030 |
CreateEntity or Instantiate(prefab) in a counted loop | One creation per entity instead of one per wave | EECS031: CreateEntities, Instantiate(prefab, span) |
Compared with other libraries
Friflo applies an EntityBatch to a query's entities, Arch adds or removes by query (whole tables move), and
DefaultEcs changes entities one by one. The same round reset of 100,000 fighters:
Stun 100,000 fighters, then lift the stun from everyone
- EasyEcs
- Other libraries
BenchmarkDotNet 0.15.2, .NET 10.0.13, Intel Xeon Processor 2.10GHz, 4 cores, Ubuntu 24.04.5 LTS.
Data table
| Library | Case | Mean | vs EasyEcs | Allocated |
|---|---|---|---|---|
| EasyEcs | SetAllRemoveAll | 78.7 μs | 1.00× | 0 B |
| Friflo.Engine.ECS | ApplyBatch | 12.1 ms | 154× | 4.00 MB |
| Arch | AddRemoveByQuery | 1.21 ms | 15× | 0 B |
| DefaultEcs | PerEntity | 8.12 ms | 103× | 0 B |
And a volley of 10,000 shots spawned beside 100,000 fighters, then cleared:
Spawn 10,000 shots, then destroy them all
- EasyEcs
- Other libraries
BenchmarkDotNet 0.15.2, .NET 10.0.13, Intel Xeon Processor 2.10GHz, 4 cores, Ubuntu 24.04.5 LTS.
Data table
| Library | Case | Mean | vs EasyEcs | Allocated |
|---|---|---|---|---|
| EasyEcs | CreateAndDestroyAll | 138 μs | 1.00× | 0 B |
| Friflo.Engine.ECS | PerEntity | 380 μs | 2.75× | 0 B |
| Arch | CreateAndDestroyByQuery | 409 μs | 2.96× | 0 B |
| DefaultEcs | PerEntity | 1.33 ms | 9.7× | 313 KB |
Related
Last updated on
How is this guide?
Structural changes
Create, destroy, add and remove components in the middle of a pass. EasyEcs applies them at once, with no command buffer, visiting each entity at most once.
Cleanup and disable
Release outside resources exactly once with ICleanupComponent, pause a component with Disable<T> and switch whole entities off in a C# ECS.