Skip to content

Systems, Queries & Scheduling

Systems are where behavior lives. They declare the components they need, iterate matching entities, and mutate through command buffers.

Queries describe which archetypes a system should see:

  • Basic filters: Query.and(...), Query.or(...), Query.not(...) combine component requirements.
  • Archetype shortcuts: Archetype.of(Position, Velocity) builds a query from a component set.
  • Exact matches: ExactArchetypeQuery targets entities with exactly that component set.
  • Read/write intent: ReadWriteQuery (present in the jar) can express access intent when needed.

Validate queries against the registry once and reuse them; avoid rebuilding them inside inner loops.

SystemEntry pointTypical use
TickableSystemtick(dt, threadIndex, store)Store-wide updates without per-entity iteration.
ArchetypeTickingSystemtick(dt, chunk, store, cmd)Chunk-level logic with command buffer access.
EntityTickingSystemtick(dt, entityIndex, chunk, store, cmd)Per-entity logic; set isParallel if safe to run across threads.
DelayedSystem / DelayedEntitySystemdelayedTick / tickRun every N seconds using built-in delayed data resources.
SpatialSystemtick(dt, chunk, store, cmd) + getPositionSystems that need spatial indexing.
EventSystemhandle(...)React to ECS events (entity or world level).
DataSystemfetch(...)Batch, read-only data gathering without mutations.
  • Entity events: EntityEventSystem runs per matching entity when Store.invoke(ref, event) or Store.invoke(entityEventType, ref, event) is called.
  • World events: WorldEventSystem runs once per store on Store.invoke(event) or Store.invoke(worldEventType, event).
  • Events can be cancellable by extending CancellableEcsEvent.

Control execution order explicitly instead of relying on registration order:

  • Systems can return a set of Dependency objects targeting a system class, system type, or system group.
  • Order.BEFORE/AFTER and OrderPriority (CLOSEST..FURTHEST) fine-tune placement.
  • SystemGroup lets related systems share ordering; groups themselves can declare dependencies.
  • The registry validates references and topologically sorts the graph before ticking.
  • Iterate over ArchetypeChunk or entity indices, but buffer mutations through the provided CommandBuffer.
  • Use fork()/mergeParallel() if you build your own parallel loops inside a system.
  • Keep queries stable; avoid adding/removing component types mid-iteration unless buffered.
  • Model each concern as a small system with a narrow query.
  • Prefer component tags (e.g., NonTicking) to toggle behavior without branching in systems.
  • Keep system names and dependencies explicit so future mods can compose with yours.
  • Use data systems when you need snapshots without mutating state (e.g., exporting entity lists).

Next: explore the built-in components and ECS events you can reuse.