Listen for value changes of an Entity
eriksachse opened this issue · 1 comments
In the docs it says ...will re-render when the query results change.
https://github.com/isaac-mason/arancini/tree/main/packages/arancini-react#usequery
But when querying e.g. health props of an entity, it doesn't show until you rerender a component.
CBS
This is the expected behaviour, but I will update the docs to make that clearer! The useQuery
hook will re-render only when entities are added to or removed from a query. If a component value is changed/mutated, useQuery
won't rerender.
You'd need to do change detection for component values in user-land. There are many ways you could do this. Just some examples:
- If you only need to do this for a small number of components, you could break some conventional entity component system rules around components being purely data. You could, for example, have a component that is a mini reactive store, or have a component that has an "onChange" event emitter.
- You could have a "dirty" component, add that component when the component value changes, and have a query like
(e) => e.all('myComponent', 'dirty')
- If you're rendering something like a healthbar, you could just check the health value every frame
I've been apprehensive about doing this in the library itself, I haven't settled on a good approach yet. This may change in future 🙂