diff --git a/crates/bevy_ecs/src/reflect.rs b/crates/bevy_ecs/src/reflect.rs index d1f4897b00fd7..f798b753f94f5 100644 --- a/crates/bevy_ecs/src/reflect.rs +++ b/crates/bevy_ecs/src/reflect.rs @@ -10,6 +10,7 @@ use bevy_reflect::{impl_reflect_value, FromType, Reflect, ReflectDeserialize}; pub struct ReflectComponent { add_component: fn(&mut World, Entity, &dyn Reflect), apply_component: fn(&mut World, Entity, &dyn Reflect), + remove_component: fn(&mut World, Entity), reflect_component: fn(&World, Entity) -> Option<&dyn Reflect>, reflect_component_mut: unsafe fn(&World, Entity) -> Option, copy_component: fn(&World, &mut World, Entity, Entity), @@ -24,6 +25,10 @@ impl ReflectComponent { (self.apply_component)(world, entity, component); } + pub fn remove_component(&self, world: &mut World, entity: Entity) { + (self.remove_component)(world, entity); + } + pub fn reflect_component<'a>( &self, world: &'a World, @@ -83,6 +88,9 @@ impl FromType for ReflectComponent { let mut component = world.get_mut::(entity).unwrap(); component.apply(reflected_component); }, + remove_component: |world, entity| { + world.entity_mut(entity).remove::(); + }, copy_component: |source_world, destination_world, source_entity, destination_entity| { let source_component = source_world.get::(source_entity).unwrap(); let mut destination_component = C::from_world(destination_world);