From 9befeea56191776bb288292f6dcba1f945f7302c Mon Sep 17 00:00:00 2001 From: Raymond Date: Sat, 26 Sep 2020 14:27:56 -0700 Subject: [PATCH] Add remove bundle to bevy_ecs commands (#579) add remove bundle to bevy_ecs commands --- crates/bevy_ecs/src/system/commands.rs | 27 ++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/crates/bevy_ecs/src/system/commands.rs b/crates/bevy_ecs/src/system/commands.rs index be0c4570a1da2..48e9f6cd3474b 100644 --- a/crates/bevy_ecs/src/system/commands.rs +++ b/crates/bevy_ecs/src/system/commands.rs @@ -112,6 +112,23 @@ where } } +pub(crate) struct Remove +where + T: Bundle + Send + Sync + 'static, +{ + entity: Entity, + phantom: PhantomData, +} + +impl WorldWriter for Remove +where + T: Bundle + Send + Sync + 'static, +{ + fn write(self: Box, world: &mut World) { + world.remove::(self.entity).unwrap(); + } +} + pub trait ResourcesWriter: Send + Sync { fn write(self: Box, resources: &mut Resources); } @@ -319,6 +336,16 @@ impl Commands { }) } + pub fn remove(&mut self, entity: Entity) -> &mut Self + where + T: Bundle + Send + Sync + 'static, + { + self.write_world(Remove:: { + entity, + phantom: PhantomData, + }) + } + pub fn set_entity_reserver(&self, entity_reserver: EntityReserver) { self.commands.lock().entity_reserver = Some(entity_reserver); }