-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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 EntityCommands.retain
and EntityWorldMut.retain
#10873
Conversation
…red functionality of remove and retain, with the added bonus of less safety invariants outside of this function.
} | ||
|
||
/// Removes any components in the [`Bundle`] from the entity. | ||
// TODO: BundleRemover? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This TODO isn't clear to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know what this todo is referring to, it was already on remove
so I left it there
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Going back through the commits looks like it's referring to a potential API to aggregate Bundle
operations into builder APIs like a BundleRemover
cause it also appears on other bundle operations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great public docs, useful API, sensible implementation. Nice stuff.
Before merging, we should add some unit tests to verify that this continues to work as expected.
…`retain_nothing` checking clearing an entity (with `()`) and `retain_some_components` checking normal behaviour, including retaining a component that isn't on the entity.
Objective
Adds
EntityCommands.retain
andEntityWorldMut.retain
to remove all components except the given bundle from the entity.Fixes #10865.
Solution
I added a private unsafe function in
EntityWorldMut
calledremove_bundle_info
which performs the shared behaviour ofremove
andretain
, namely taking aBundleInfo
of components to remove, and removing them from the given entity. Thenretain
simply gets all the components on the entity and filters them by whether they are in the bundle it was passed, before passing thisBundleInfo
intoremove_bundle_info
.EntityCommands.retain
just creates a new typeRetain
which runsEntityWorldMut.retain
when run.Changelog
Added
EntityCommands.retain
andEntityWorldMut.retain
, which remove all components except the given bundle from the entity, they can also be used to remove all components by passing()
as the bundle.