Querying hierarchies? #5498
-
What's the most optimized way to query for a certain hierarchy of items? I am implementing an RTS camera that I need to orbit around a pivot which will be moving. I skimmed through the docs and seen only a possibility to query for entities with children/a parent, without specifying what components does the parent/the children have. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
One thing that is possible now in Bevy 0.8 is iterating over fn children(query: Query<&Children>, text_query: Query<&Text>) {
for children in query.iter() {
for child in text_query.iter_many(children) {
info!("{}", child.sections[0].value);
}
}
} But other than that, we pretty much have to do a lot of manual work with multiple queries, e.g. fn parent(query: Query<&Parent>, text_query: Query<&Text>) {
for parent in query.iter() {
for text in text_query.get(parent.get()) {
info!("{}", text.sections[0].value);
}
}
} It's also possible to construct recursive queries like this: #838 (comment) (updating visibility hierarchies this way is thankfully no longer necessary with Bevy 0.8) There's ongoing discussion about entity-entity relations here: |
Beta Was this translation helpful? Give feedback.
One thing that is possible now in Bevy 0.8 is iterating over
Children
withiter_many
.But other than that, we pretty much have to do a lot of manual work with multiple queries, e.g.
It's also possible to construct recursive queries like this: #838 (comment) (upda…