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

[Merged by Bors] - feat: remove_component for ReflectComponent #2682

Closed
wants to merge 1 commit into from
Closed

Conversation

gschup
Copy link
Contributor

@gschup gschup commented 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

@github-actions github-actions bot added the S-Needs-Triage This issue needs to be labelled label Aug 18, 2021
@alice-i-cecile alice-i-cecile added A-Reflection Runtime information about types C-Feature A new feature, making something new possible and removed S-Needs-Triage This issue needs to be labelled labels Aug 18, 2021
@DJMcNab DJMcNab added the S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it label Aug 18, 2021
@cart
Copy link
Member

cart commented Aug 18, 2021

bors r+

@cart
Copy link
Member

cart commented Aug 18, 2021

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
@bors bors bot changed the title feat: remove_component for ReflectComponent [Merged by Bors] - feat: remove_component for ReflectComponent Aug 18, 2021
@bors bors bot closed this Aug 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Reflection Runtime information about types C-Feature A new feature, making something new possible S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants