Skip to main content

Interface: EcsSystem<TQuery>

Defined in: ecs/ecs-system.ts:12

A unit of per-tick logic that operates on all entities matching its query (and tags, if given) in a single batch call. Register an instance with EcsWorld.addSystem to have update invoked every EcsWorld.update call.

Type Parameters​

TQuery​

TQuery extends readonly unknown[] = readonly unknown[]

The tuple of component data types the system reads, in query order. Matches the array of ComponentKeys in query.

Properties​

name?​

optional name?: string

Defined in: ecs/ecs-system.ts:20

An optional human-readable name, used to identify the system in error messages (e.g. when a before/after ordering constraint given to EcsWorld.addSystem can't be satisfied).


query​

query: KeysFromComponents<TQuery>

Defined in: ecs/ecs-system.ts:26

The component keys an entity must have for this system to query it. Order determines the order of arrays inside queryResult.components.


tags?​

optional tags?: TagKey[]

Defined in: ecs/ecs-system.ts:32

Additional tag keys an entity must have for this system to query it. Unlike query, tags don't contribute values to queryResult.components.

Methods​

cleanup()?​

optional cleanup(world): void

Defined in: ecs/ecs-system.ts:59

Invoked once when the system is removed from an EcsWorld or when the world is stopped via EcsWorld.stop. Use it to release resources acquired during system lifetime or execution.

Parameters​

world​

EcsWorld

The EcsWorld releasing the system.

Returns​

void


onRegister()?​

optional onRegister(world): void

Defined in: ecs/ecs-system.ts:40

Invoked once when the system is registered with an EcsWorld. Use it to acquire resources or set up state the system will need for its lifetime.

Parameters​

world​

EcsWorld

The EcsWorld the system was registered with.

Returns​

void


update()​

update(world, queryResult): void

Defined in: ecs/ecs-system.ts:50

Invoked once per tick with all entities and components matching query (and tags). The system handles its own iteration, enabling operations across all matched entities (e.g., spatial partitioning, batching, or sorting).

Parameters​

world​

EcsWorld

The EcsWorld running this system.

queryResult​

QueryResult<TQuery>

The batch of matched entity IDs and their corresponding component data.

Returns​

void