Troubleshooting
What each EasyEcs exception message means and how to fix it, and why a system does not run, a generated member is missing or a save drops data.
Most mistakes never reach run time: the analyzer rejects them while you type. This page is for the rest: the exceptions EasyEcs throws, quoted as they appear, and the problems that throw nothing. Search the page for the first words of your message.
| Message starts with | Section |
|---|---|
A structural change started while another one was running | Two structural changes at once |
A structural change was made while the world's structure is frozen | A change while the structure is frozen |
Entity is not alive | A stale or default handle |
Entity has no X component | A missing component |
Singleton X was not added to this world | A missing singleton |
The entity has no X (check HasValue) | An empty Maybe<T> |
X already belongs to a world | A system added twice |
[UpdateBefore] / [UpdateAfter] form a cycle | An ordering cycle |
The ChildOf links form a cycle | A ChildOf cycle in Descendants |
X cannot be disabled: remove it instead | Disabling a cleanup component or ChildOf |
Snapshots cannot be captured or restored while a query iterates, Types cannot be removed during a pass | Calls that wait for the end of a pass |
Not an EasyEcs save, The size of X changed, The fields of X changed, X was saved as, Types of this process share the save id, A damaged save | A save that does not load |
Why does a structural change throw "started while another one was running"?
InvalidOperationException: A structural change started while another one was running on this world: structural
changes are made by the world's owner thread, one at a timeTwo structural changes (create, destroy, Set, Remove, a singleton or system added) overlapped on one world. Either
a second thread changed the world while its owner did, or code running inside a change (a callback of your own around
EasyEcs calls) started another. EasyEcs checks a plain flag, so it catches many such races, not all of them.
Fix: change a world from one thread at a time. Other threads hand their changes over as data, through a queue a system drains on the owner's thread (input from other threads, hosting), or each thread gets its own world.
Why does a structural change throw "while the world's structure is frozen"?
InvalidOperationException: A structural change was made while the world's structure is frozen (systems or a parallel
[ForEach] running on several threads, or a batch job holding spans into the tables)The change was made while other code held the tables still: inside a parallel stage of systems
(ParallelSystems), a [ForEach(Parallel = true)] method, a batch method or ForEachBatch job (spans point into
the columns), or a job marked INoStructuralChanges. The analyzer reports the changes it sees there
(EECS010, EECS013); this one came through a
helper or a handle it could not follow.
Fix: record the change as data (a tag, a component, a request entity) and make it in a system or [ForEach]
method that runs alone: one that takes Entity or World, or an OnUpdate.
Why is my entity "not alive"?
InvalidOperationException: Entity is not alive (destroyed, or a default handle)Get, GetOrAdd, Set, Remove or Destroy was called on a handle whose entity was destroyed (its id may already
belong to another entity: the version tells them apart), or on default(Entity). Questions answer false instead of
throwing: IsAlive, Has<T>() and TryGet<T>().
Fix: check entity.IsAlive where an entity may have died since you took its handle, and keep EntityIds in
components, resolving them with world.TryGetEntity(id, out var entity)
(entities and components).
Why does Get<T>() say the entity has no component?
InvalidOperationException: Entity has no Mana componentGet<T>() (and the generated entity.Mana) needs the component; a component that was removed or
disabled counts as absent. Fix: TryGet<T>(out var value) or the generated
TryGetMana(out …) where it is optional, GetOrAdd<T>() to add a default, or in a [ForEach] method a
Maybe<T> parameter or a second method split by [With<T>] / [Without<T>].
Why is a singleton "not added to this world"?
InvalidOperationException: Singleton Clock was not added to this world: set it before the systems that read it run
(world.SetClock(...) or world.AddSingleton<Clock>()), or use GetOrAddClock() where a default is meantCode read a singleton nobody added: world.GetSingleton<T>(), the generated world.Clock, world.SingletonRef<T>(),
or a [ForEach] method that takes Clock as a parameter. A parameter is resolved when its system runs, so the first
Update() throws, even when no entity matches. The world does not invent the singleton, because its default is
rarely right: a clock with no step would leave every entity standing still, with no error to point at the missing
setup (singletons).
Fix: add it where the world is built, before the first Update() (world.SetClock(…),
world.AddSingleton<Clock>()), or use GetOrAddSingleton<T>() / GetOrAddClock() where a default value is right.
Why does Maybe<T>.Value throw?
InvalidOperationException: The entity has no Mana (check HasValue)The entity the method visits has no T. Fix: test HasValue before reading Value
(Maybe<T>).
Why does AddSystem say the system "already belongs to a world"?
InvalidOperationException: ReceiveSpawns already belongs to a worldA system instance lives in one world. Fix: create one instance per world (world.AddSystem<T>() creates a new
one each time). Note that the same system type can be added twice to one world, and then runs twice per update.
Why does AddSystem report a cycle?
InvalidOperationException: [UpdateBefore] / [UpdateAfter] form a cycle among A, BThe orderings of the named systems cannot all hold. The analyzer reports the cycles it sees in one compilation (EECS019); this one spans assemblies. Fix: remove one of the orderings.
Why does Descendants throw "The ChildOf links form a cycle"?
InvalidOperationException: The ChildOf links form a cycleworld.Descendants(root) met an entity it had already visited: an entity is its own ancestor, because a Set(new ChildOf(…)) made a parent the child of one of its descendants. EasyEcs does not check a re-parent (that would be a
walk up the tree on every Set), so the walk finds the cycle when it reaches it.
Fix: before re-parenting child under parent, walk up from parent through ChildOf and refuse when you meet
child. Detach first (Remove<ChildOf>()) when an entity moves under one of its own descendants
(re-parent and detach).
Why can a component not be disabled?
InvalidOperationException: ChildOf cannot be disabled: remove it insteadDisable<T>() keeps a value hidden from queries. A cleanup component and
ChildOf cannot be hidden that way: the world must keep seeing them to finish a destroy and keep a hierarchy. Fix:
remove the component, or disable another component that systems filter on.
Why must Capture, Restore or RemoveTypes wait for a pass?
InvalidOperationException: Snapshots cannot be captured or restored while a query iterates
InvalidOperationException: Types cannot be removed during a passThey rewrite or drop whole tables, which a foreach over a query or a running system is walking. Fix: call them
between updates, outside any query loop (snapshots,
unloading). Restore also refuses a snapshot of another world
(ArgumentException) and one taken before RemoveTypes dropped some of its tables.
Why does a save not load?
InvalidDataException: Not an EasyEcs save (or one of another format version)
InvalidDataException: The size of Stock changed (8 bytes saved, 12 now): its saves cannot be loaded (…)
InvalidDataException: The fields of Stock changed since the save: its saves cannot be loaded (…)
InvalidDataException: Stock was saved as raw rows and is written by its Nino formatter now: its saves cannot be loaded
InvalidDataException: Types of this process share the save id … (…): unload or rename one of them (…)
InvalidDataException: A damaged save: …A load checks every component against the code that reads it, and a refused load leaves the world as it was.
- Not an EasyEcs save: the bytes are something else, cut short, or written by another save format version (a save of EasyEcs 4.3 or earlier).
- Size or fields changed: a raw unmanaged component's fields were added, removed, renamed or retyped since the
save, or a
[NinoType]component changed in a way its Nino format does not allow. Make a component whose shape will change a[NinoType]with theVersionTolerantorKeyedformat, or keep the old type and convert it in a system (when the code changed). - Raw rows and Nino:
[NinoType]was added to or removed from an unmanaged component since the save. - A shared save id: two types of the process have one id: the same namespace-qualified name (two versions of a
plugin loaded at once), or a
[NinoFormerName]that is another type's name. Unload the old version first, or rename one of them. - A damaged save: a count or an id is out of range, or a buffer is longer than its bytes: the bytes are corrupt.
Why does my system never run?
Check, in this order:
- It was added to this world:
world.Systemslists every system. - It is enabled:
Enabledis true, andErroris null. UnderSystemErrorPolicy.Disablean exception switched it off; settingEnabled = trueclears the error and retries. - Its group is updated: a system with
[UpdateInGroup<G>]runs only onworld.Update<G>(), never onworld.Update(). - Its interval is due: with
UpdateInterval => N, it runs on every N-th update of its group, first on the N-th, shifted byUpdatePhase. - Its filters match: count what the method needs with
world.Count<T…>(filter). The group's filters apply to every method of the group:[With<T>],[Without<T>]and[WithAny<T>]on the group struct, andIGroupWith<T>/IGroupWithout<T>from the group or any interface it implements (a generic actor interface carries them). A disabled component counts as absent. - There was something to see: a
[Changed<T>]method visits only rows written since its system last ran, and a[Removed<T>]method only entities that lostTsince then (change tracking).
WorldOptions.MeasureSystems counts every run in system.Stats.Runs, which tells "never ran" from "ran and did
nothing".
Why does entity.Run return false?
entity.Run<T…, TJob>(ref job, filter) runs the job only when the entity can take it, and says false, without
running it, when:
- The entity is not alive: destroyed since you took its handle, or
default(Entity).Rundoes not throw for it, unlikeGet. - It lacks a component the job takes: every type argument before
TJobmust be present (a disabled component counts as absent). Check withentity.Has<T1, T2>(). - It fails the filter: a
Without<T>it has, aWithAnyit misses, aChanged<T>(tick)it was not written since, a group it is not in. Run once without the filter to tell this case from the others.
Fix: treat false as the answer to the request (the actor is gone, the unit is dead) rather than an error, and
look up the entity again by its EntityId when it may have been replaced
(one entity: entity.Run).
Why do my systems not run in parallel?
With ParallelSystems, a system shares a stage only when its access is known and does not conflict. A system runs
alone when it takes an Entity or World parameter, has an instance [ForEach] method, overrides OnUpdate, or has
no [ForEach] method. Two systems conflict when one writes what the other reads or writes, and a ref parameter
counts as a write even when the body only reads it: use in
(parallel systems). An ordering ([UpdateAfter<T>]) also puts the later
system in a later stage.
Why is a generated member missing?
The generator writes entity.Health, SetHealth(…), world.Clock and the others as C# 14 extension members. It
writes nothing when:
- The project compiles with a language version below C# 14 (
<LangVersion>set lower than the .NET 10 default). - The type is generic, or nested in a type the generated code cannot see.
- The receiver already has a member of that name: a component named
Idgets noentity.Id(the handle has one), and a member you wrote yourself wins. - The component is indexed (
IIndexed<TKey>): it has noGetOrAddX(), andentity.Xis read-only; write it withSetX(…).
The generic API always works: Get<T>(), Read<T>(), Set(…), Has<T>(), Remove<T>(), GetSingleton<T>()
(generated members).
Why did a value I wrote through a ref disappear?
A ref from entity.Get<T>() or a query item is valid until the next structural change of
the world, which can move rows, and never across an await. A write through an older ref lands in memory the entity
no longer uses. Read again through the handle after the change (refs and await).
A tracked or indexed component is read-only through entity.X and Read<T>(): writes go through Set(…), or the
generated WriteX() for a tracked one, so that the change is stamped
(change tracking).
Why did a component vanish after a load?
A save names each type by its Nino type id (a hash of its namespace-qualified name), and a load skips the types this
process does not have. A component renamed or moved to another namespace since the save loads as missing: its data is
dropped without an error. Put [NinoFormerName("Old.Namespace.Name")] on the renamed type, and its old rows load
(when the code changed).
Why does the generator not see an interface another generator adds?
A component, singleton or system must declare its EasyEcs interface (IComponent, ITrackChanges,
IIndexed<TKey> and the others) in code you wrote. Source generators all run on the same input and none sees the
others' output, so when another generator adds IComponent to a partial type, EasyEcs's generator never learns that
the type is a component: it writes no members for it, and a load finds the type only once the process has used
it. Write the interface on your own
declaration; the other generator may still add its members to the same partial type.
Why does my actor key crash with a stack overflow in ToString?
A record struct that is its own key (IIndexed<TSelf>, the actor pattern) and implements Key as a public property,
public Shop Key => this;, prints its public properties in ToString(): Key prints the record, which prints Key,
until the stack overflows. A log line, a string interpolation or the debugger's view of the value is enough to
trigger it.
Fix: implement Key explicitly, Shop IIndexed<Shop>.Key => this;: the index still finds it, and ToString()
no longer sees it (common mistakes).
Related
Last updated on
How is this guide?
Common mistakes
Twenty-four mistakes people make with EasyEcs in C#, each with the code you might write, why it is wrong and the fix, plus the analyzer rule behind it.
Comparison with other ECS libraries
Which C# ECS is fastest? EasyEcs against Friflo.Engine.ECS, Arch and DefaultEcs, feature by feature: every benchmark sorted by lead, losses explained.