-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
# Objective Adds `EntityCommands.retain` and `EntityWorldMut.retain` to remove all components except the given bundle from the entity. Fixes #10865. ## Solution I added a private unsafe function in `EntityWorldMut` called `remove_bundle_info` which performs the shared behaviour of `remove` and `retain`, namely taking a `BundleInfo` of components to remove, and removing them from the given entity. Then `retain` simply gets all the components on the entity and filters them by whether they are in the bundle it was passed, before passing this `BundleInfo` into `remove_bundle_info`. `EntityCommands.retain` just creates a new type `Retain` which runs `EntityWorldMut.retain` when run. --- ## Changelog Added `EntityCommands.retain` and `EntityWorldMut.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.
- Loading branch information
Showing
2 changed files
with
218 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters