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

Add a Removed query filter #2148

Open
alice-i-cecile opened this issue May 12, 2021 · 3 comments
Open

Add a Removed query filter #2148

alice-i-cecile opened this issue May 12, 2021 · 3 comments
Labels
A-ECS Entities, components, systems, and events C-Feature A new feature, making something new possible C-Usability A targeted quality-of-life change that makes Bevy easier to use S-Needs-Design-Doc This issue or PR is particularly complex, and needs an approved design doc before it can be merged

Comments

@alice-i-cecile
Copy link
Member

alice-i-cecile commented May 12, 2021

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

The existing RemovedComponent API is somewhat unclear and cumbersome. It also commonly requires a manual query filtering step to make use of, which is both slow and full of boilerplate.

What solution would you like?

I want to be able to add Removed<T> to my queries as a filter to only include entities that have had the component removed since the system last ran using reliable change detection.

What alternative(s) have you considered?

We could also store the values of the removed components, but that won't be feasible with reliable change detection.

Additional context

With the addition of subworlds / multiple worlds (bevyengine/rfcs#16), we could move removed components to a parallel purgatory subworld for two frames using a double-buffer pattern, allowing us the ability to access removed data.

#13928 offers another way to remove RemovedComponents, which should be pursued. It may still be worth having a Removed filter after that, but its value is much less clear.

@alice-i-cecile alice-i-cecile added C-Feature A new feature, making something new possible A-ECS Entities, components, systems, and events C-Usability A targeted quality-of-life change that makes Bevy easier to use labels May 12, 2021
@lukewestby
Copy link

lukewestby commented May 12, 2021

Could this be implemented prior to subworlds just as a filter, in such a way that Query<&MyComponent, Removed<MyComponent>> would be empty? I think that such an implementation would be useful - as you said, Query<Entity, (Removed<MyComponent>, OtherFilter)> is a lot nicer than RemovedComponents<MyComponent> and manual filtering. However, it could be confusing to later totally change the semantics of the query using subworlds so that Query<&MyComponent, Removed<MyComponent>> does return data.

@alice-i-cecile
Copy link
Member Author

Yep, this should be totally feasible before subworlds. I think that only allowing it in the filter position for now is just fine; we're always going to want that ability.

Once we can access the removed data I think that the correct approach is to do something like Query<MyData, (), Purgatory> with the third type parameter representing the world it's drawing from rather than trying to implicitly overload the Removed type with different durations based on which position it's in.

@alice-i-cecile
Copy link
Member Author

From my draft of the relevant section of the book:

  1. While Added and Changed operate on the basis of "since the last time this system ran", removal detection only works for the last frame. This distinction is very important if your system does not run every frame due to states or run criteria.
  2. RemovedComponents does not return the value of the component that was removed, due to performance concerns. If you need this, you will need to include your own change-detecting system to cache the values before they are removed.
  3. RemovedComponents is a system parameter, not a query filter. As a result, you will have to manually compare it to the results of a query if you only need to handle some subset of component removal events.

@Nilirad Nilirad mentioned this issue Aug 6, 2021
@alice-i-cecile alice-i-cecile added the S-Needs-Design-Doc This issue or PR is particularly complex, and needs an approved design doc before it can be merged label Dec 12, 2021
@alice-i-cecile alice-i-cecile changed the title Replace RemovedComponents with a Removed query filter Add a Removed query filter Jun 19, 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 C-Usability A targeted quality-of-life change that makes Bevy easier to use S-Needs-Design-Doc This issue or PR is particularly complex, and needs an approved design doc before it can be merged
Projects
None yet
Development

No branches or pull requests

2 participants