Iterate over all entities in a world
Bevy version: 0.20Last updated:
We can use an EntityRef by taking the &mut World system parameter and reading directly from the world.
An EntityRef is a read-only reference to an Entity and its components.
fn do_crazy_things(world: &mut World) {
// we can do anything with any data in the Bevy ECS here!
let mut query = world.query::<EntityRef>();
for entity_ref in query.iter(world) {
// ...
}
}
A system that takes &mut World is exclusive. It needs access to the entire world, so it cannot run in parallel with any other system and should run at the end of all other systems. Its performance will be limited.