[Merged by Bors] - feat: remove_component for ReflectComponent#2682
Closed
gschup wants to merge 1 commit intobevyengine:mainfrom
gschup:main
Closed
[Merged by Bors] - feat: remove_component for ReflectComponent#2682gschup wants to merge 1 commit intobevyengine:mainfrom gschup:main
gschup wants to merge 1 commit intobevyengine:mainfrom
gschup:main
Conversation
alice-i-cecile
approved these changes
Aug 18, 2021
DJMcNab
approved these changes
Aug 18, 2021
mockersf
approved these changes
Aug 18, 2021
Member
|
bors r+ |
Member
|
Nice easy win. Love it! |
bors bot
pushed a commit
that referenced
this pull request
Aug 18, 2021
# Objective While implementing a plugin for my rollback networking library, I needed to load/save parts of the world. For this, I made a WorldSnapshot that works quite like the current DynamicScene. Using a TypeRegistry to register component types I want to save/load and then using ReflectComponents methods to add or apply components of the given types. However, I noticed there is no method to remove components from entities through the ReflectComponent. ## Solution I added a `remove_component` field to the `ReflectComponent` struct, as well as a `pub fn remove_component(&self, world: &mut World, entity: Entity)` to call that function in `remove_component`. This follows exactly the same pattern all other methods/fields in this struct look like. This is an example how it could be used (at least how I would use it): https://github.com/gschup/bevy_ggrs/blob/6c003f86f1993bcbb21c180fab2e8ef664b7f7c9/src/world_snapshot.rs#L133
Contributor
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Objective
While implementing a plugin for my rollback networking library, I needed to load/save parts of the world. For this, I made a WorldSnapshot that works quite like the current DynamicScene. Using a TypeRegistry to register component types I want to save/load and then using ReflectComponents methods to add or apply components of the given types.
However, I noticed there is no method to remove components from entities through the ReflectComponent.
Solution
I added a
remove_componentfield to theReflectComponentstruct, as well as apub fn remove_component(&self, world: &mut World, entity: Entity)to call that function inremove_component. This follows exactly the same pattern all other methods/fields in this struct look like.This is an example how it could be used (at least how I would use it):
https://github.com/gschup/bevy_ggrs/blob/6c003f86f1993bcbb21c180fab2e8ef664b7f7c9/src/world_snapshot.rs#L133