I had some code like this to delete all entities in my code to reset everything on a button press.
for (entity, _) in world.iter() {
world.despawn(entity);
}
But I run into a borrowing issue as world cannot be borrowed as mutable while also being iterated on. Maybe a iter_mut() would be desired on world?
To solve the issue I collect the ID's in a Vec before de-spawning but this seems inefficient for large numbers of entities. Maybe a simple clear method on world would be useful?
let ids = world.iter().map(|(id, _)| id).collect::<Vec<_>>();
for id in ids {
world.despawn(id);
}
All in all, just a small issue I ran into with some ideas for possible improvement. I'm loving the crate so far. The simplicity and freedom is wonderful!
I had some code like this to delete all entities in my code to reset everything on a button press.
But I run into a borrowing issue as world cannot be borrowed as mutable while also being iterated on. Maybe a
iter_mut()would be desired on world?To solve the issue I collect the ID's in a
Vecbefore de-spawning but this seems inefficient for large numbers of entities. Maybe a simple clear method on world would be useful?All in all, just a small issue I ran into with some ideas for possible improvement. I'm loving the crate so far. The simplicity and freedom is wonderful!