QueryInstance
Defined in: ecs/query.ts:395
A live query, as a system body receives it. Iterate it — each step yields the
entity followed by its components — or use forEach, single, toArray,
count and isEmpty. Any Mut argument is written back and marked
changed as iteration leaves each entity, so leaving the loop early is safe.
Type Parameters
Section titled “Type Parameters”C extends readonly QueryArg[]
Implements
Section titled “Implements”Iterable<QueryResult<C>>
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new QueryInstance<
C>(world,descriptor,lastRunTick?):QueryInstance<C>
Defined in: ecs/query.ts:416
Parameters
Section titled “Parameters”descriptor
Section titled “descriptor”lastRunTick?
Section titled “lastRunTick?”number = -1
Returns
Section titled “Returns”QueryInstance<C>
Methods
Section titled “Methods”[iterator]()
Section titled “[iterator]()”[iterator]():
Iterator<[number,...ComponentsData<C>[]]>
Defined in: ecs/query.ts:567
Rows the caller may keep: a fresh array per entity, and for an engine-backed component a fresh value rather than the shared fill target. forEach lends its row instead and is cheaper for a body that only reads it once.
Returns
Section titled “Returns”Iterator<[number, ...ComponentsData<C>[]]>
Implementation of
Section titled “Implementation of”Iterable.[iterator]
count()
Section titled “count()”count():
number
Defined in: ecs/query.ts:768
How many results iterating would yield. Added()/Changed() are per-entity tick checks rather than part of the entity set the cache returns, so counting has to apply them too — the same pass the iterator makes.
Returns
Section titled “Returns”number
forEach()
Section titled “forEach()”forEach(
callback):void
Defined in: ecs/query.ts:670
Run callback per matching entity, LENDING it the row: the values are
refilled for the next entity, so anything kept past the callback must be
copied. The fast path — iterating instead costs an allocation per row
(1.2x for script components, 1.7x for engine-backed ones).
Parameters
Section titled “Parameters”callback
Section titled “callback”(entity, …components) => void
Returns
Section titled “Returns”void
isEmpty()
Section titled “isEmpty()”isEmpty():
boolean
Defined in: ecs/query.ts:754
Whether iterating would yield nothing. Asks the entity set rather than running the iterator: taking one step of a Mut() query writes that entity back and records a Changed tick for it, and asking whether a query is empty must not mark anything as having changed.
Returns
Section titled “Returns”boolean
single()
Section titled “single()”single(): [
number,...ComponentsData<C>[]] |null
Defined in: ecs/query.ts:743
The one row, or null. The iterator’s rows are already the caller’s to keep.
Returns
Section titled “Returns”[number, ...ComponentsData<C>[]] | null
toArray()
Section titled “toArray()”toArray(): [
number,...ComponentsData<C>[]][]
Defined in: ecs/query.ts:779
Returns
Section titled “Returns”[number, ...ComponentsData<C>[]][]