Skip to content

Deleting all entities #2

Description

@JohnDoneth

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions