Query
In one line: a question you ask of your data — by component shape, field value, or geometry — evaluated against a transaction's snapshot.
A query starts from tx.Query<Unit>(), which returns a builder you refine with chainable filters: With/Without/Enabled (component shape), Where (any predicate, broad scan) vs WhereField (an indexed field, targeted scan), and spatial predicates (WhereNearby/WhereInAABB/WhereRay). Nothing runs until a terminal: Execute (materialise ids), Count, Any, or foreach.
The engine picks the scan for you — targeted (index-driven, cheap as the archetype grows), spatial, or broad (linear) — guided by lightweight statistics it maintains. Keep a query result current over time by turning it into a view.
How it relates
- Archetype — a query is typed on one:
tx.Query<Unit>(). - Index — a
WhereFieldon an indexed field drives the fast path. - Spatial index — geometric predicates run off the spatial structure.
- View — a query kept current, with deltas.
- Snapshot isolation — what a one-shot query sees.
In the API
- EcsQuery<T> — the query builder returned by
tx.Query<T>().
Learn & use
- Narrative: Guide ch.4 — querying & views
- Feature detail: lookup & range scan · spatial query API