Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filtered observers #15287

Open
alice-i-cecile opened this issue Sep 18, 2024 · 0 comments
Open

Filtered observers #15287

alice-i-cecile opened this issue Sep 18, 2024 · 0 comments
Labels
A-ECS Entities, components, systems, and events C-Feature A new feature, making something new possible D-Modest A "normal" level of difficulty; suitable for simple features or challenging fixes X-Uncontroversial This work is generally agreed upon

Comments

@alice-i-cecile
Copy link
Member

alice-i-cecile commented Sep 18, 2024

What problem does this solve or what need does it fill?

When working with lifecycle observers (OnAdd, OnRemove, OnInsert and OnReplace), simply watching for changes to a single component type is often too broad. Instead, it's common to want to filter for the addition / removal of a component and the presence of another component.

What solution would you like?

Add another generic F to Trigger, which ensures that entities match that filter before observers are triggered targeting that entity.

What alternative(s) have you considered?

This can be worked around now by adding a second query to your observer, and checking if the target entity is comtained in the query. This is heavy on boilerplate for such a common pattern, and wastes work by dispatching events and repeatedly regenerating the query.

We could instead add a generic F: QueryFilter filter to OnAdd and other lifecycle observers , defaulting to (). If this generic is set, verify that the target entity matches the provided filter before triggering the observer.

On reflection, I like this solution less than modifying Trigger, as it's less general / powerful and requires more duplication. It's also less consistent with the existing B: Bundle generic, which is found on Trigger, not on e.g. OnAdd.

Additional context

#14649 is related but distinct.

#15325 proposes a change to the first generic.

Discussed on Discord with @maniwani and @NiseVoid.

@alice-i-cecile alice-i-cecile added C-Feature A new feature, making something new possible A-ECS Entities, components, systems, and events X-Uncontroversial This work is generally agreed upon D-Modest A "normal" level of difficulty; suitable for simple features or challenging fixes labels Sep 18, 2024
@alice-i-cecile alice-i-cecile changed the title Filtered lifecycle observers Filtered observers Nov 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ECS Entities, components, systems, and events C-Feature A new feature, making something new possible D-Modest A "normal" level of difficulty; suitable for simple features or challenging fixes X-Uncontroversial This work is generally agreed upon
Projects
None yet
Development

No branches or pull requests

1 participant