Iterate ALL entities (getting EntityRef/EntityMut) #5496
-
Disclaimer: I'm aware that you should be using the Query system for the majority of use cases, however I have a use-case where I need to get an EntityRef to every entity. If you need me to elaborate, let me know. To my understanding, the simplest way to achieve the question posed in the title is as follows: world.query::<Entity>().for_each(&world, |id| {
let entity_ref = world.entity(id);
// ...
}); And while this works, it smells bad to me. It feels semantically equivalent to the following: let map = HashMap::new();
for key in map.keys() {
let value = map.get(key);
} Is there a more elegant solution to iterating every entity in bevy? Cheers, |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
This is the best solution currently. Could you open a feature request issue for this? Ideally we could have a |
Beta Was this translation helpful? Give feedback.
This is the best solution currently.
World.entity
will be O(1) at least, but I expect the overhead to be relatively high compared to an optimized archetype-based solution.Could you open a feature request issue for this? Ideally we could have a
&EntityRef
or&mut EntityMut
in queries, which would automatically imply exclusive world access 🤔