Skip to content

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.

C extends readonly QueryArg[]

new QueryInstance<C>(world, descriptor, lastRunTick?): QueryInstance<C>

Defined in: ecs/query.ts:416

World

QueryDescriptor<C>

number = -1

QueryInstance<C>

[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.

Iterator<[number, ...ComponentsData<C>[]]>

Iterable.[iterator]


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.

number


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).

(entity, …components) => void

void


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.

boolean


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.

[number, ...ComponentsData<C>[]] | null


toArray(): [number, ...ComponentsData<C>[]][]

Defined in: ecs/query.ts:779

[number, ...ComponentsData<C>[]][]