Closed codedcosmos closed 2 years ago
You can do this:
struct DecaySys;
impl<'a> System<'a> for DecaySys {
type SystemData = (Entities<'a>, WriteStorage<'a, Decayable>);
fn run(&mut self, (entities, mut life): Self::SystemData) {
for (e, life) in (&entities, &mut life).join() {
log!("life: {}", life.val());
life.update();
if life.should_remove() {
entities.delete(e);
}
}
}
}
Description
Say I have a "decayable" component. Just a component that has some life but loses it over time:
and every tick it loses some life..
and when that reaches zero I want to remove the entity from the world:
How do I remove entities based on this condition in legion?
Current Implementation
I have tried making a decay system
Additional notes
I'm sure I will have to run
world.maintain();
at some point as well but that's okay.I couldn't figure out how to do this based on the documentation anywhere. Labeling this as feature-request in case it isn't because it could be added to the documentation. Perhaps this method of removing entities is bad practice. But it might be good to have some example to remove entities. (Assuming one isn't already there).
Thanks