Systems provide all the behavior of your ECS.
null so you can return it, to keep your system components tidy.
By default, all systems have a priority of
0 and are called in the order of your useSystem calls.
Pass a priority as the second parameter (lower is first) to override this behavior:
To use a system just include it anywhere within the context of an ECS.Provider:
Systems don't need to appear as direct children of ECS.Provider. Organize things however you'd like.
Use the useQuery hook:
Anytime an Entity is added or removed from the query, it will re-render the component.
However, there is also the Query.loop method:
Query.loop takes two arguments:
- a tuple of Facets types you're interested in.
- a function called for every entity matched by the query.
The callback receives two arguments:
- an entity
- the facet instances of that entity, that you requested with the tuple of types
In the example above, the query matches all entities with the
PoisonStatus. But the loop call only requests the
PoisonStatus effects, which it receives as
The facet instances passed to your callbacks are type-safe and appear in the order in which you requested them:
A tuple of
[Health, PoisonStatus] results in a tuple
[health, poison] where
health is statically-typed as
poison is statically-typed as
PoisonStatus. (Pretty cool right?)
The tuple of types you request doesn't have to be the same facets used in the query's predicate. However, it is a good idea to keep it to a subset of the facets used in the query's predicate, to ensure the entities you loop over actually have the facets you request.
The useQuery hook has a second argument where you can supply event callbacks: