Skip to content

Commit 74ad1c3

Browse files
authored
Add remove bundle to bevy_ecs commands (#579)
add remove bundle to bevy_ecs commands
1 parent 85a7f88 commit 74ad1c3

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

crates/bevy_ecs/src/system/commands.rs

+27
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,23 @@ where
112112
}
113113
}
114114

115+
pub(crate) struct Remove<T>
116+
where
117+
T: Bundle + Send + Sync + 'static,
118+
{
119+
entity: Entity,
120+
phantom: PhantomData<T>,
121+
}
122+
123+
impl<T> WorldWriter for Remove<T>
124+
where
125+
T: Bundle + Send + Sync + 'static,
126+
{
127+
fn write(self: Box<Self>, world: &mut World) {
128+
world.remove::<T>(self.entity).unwrap();
129+
}
130+
}
131+
115132
pub trait ResourcesWriter: Send + Sync {
116133
fn write(self: Box<Self>, resources: &mut Resources);
117134
}
@@ -319,6 +336,16 @@ impl Commands {
319336
})
320337
}
321338

339+
pub fn remove<T>(&mut self, entity: Entity) -> &mut Self
340+
where
341+
T: Bundle + Send + Sync + 'static,
342+
{
343+
self.write_world(Remove::<T> {
344+
entity,
345+
phantom: PhantomData,
346+
})
347+
}
348+
322349
pub fn set_entity_reserver(&self, entity_reserver: EntityReserver) {
323350
self.commands.lock().entity_reserver = Some(entity_reserver);
324351
}

0 commit comments

Comments
 (0)