Trait bevy_hierarchy::HierarchyQueryExt
source · pub trait HierarchyQueryExt<'w, 's, D: QueryData, F: QueryFilter> {
// Required methods
fn iter_descendants(
&'w self,
entity: Entity
) -> DescendantIter<'w, 's, D, F> ⓘ
where D::ReadOnly: WorldQuery<Item<'w> = &'w Children>;
fn iter_ancestors(&'w self, entity: Entity) -> AncestorIter<'w, 's, D, F> ⓘ
where D::ReadOnly: WorldQuery<Item<'w> = &'w Parent>;
}
Expand description
An extension trait for Query
that adds hierarchy related methods.
Required Methods§
sourcefn iter_descendants(&'w self, entity: Entity) -> DescendantIter<'w, 's, D, F> ⓘ
fn iter_descendants(&'w self, entity: Entity) -> DescendantIter<'w, 's, D, F> ⓘ
Returns an Iterator
of Entity
s over all of entity
s descendants.
Can only be called on a Query
of Children
(i.e. Query<&Children>
).
Traverses the hierarchy breadth-first.
§Examples
fn system(query: Query<Entity, With<Marker>>, children_query: Query<&Children>) {
let entity = query.single();
for descendant in children_query.iter_descendants(entity) {
// Do something!
}
}
sourcefn iter_ancestors(&'w self, entity: Entity) -> AncestorIter<'w, 's, D, F> ⓘ
fn iter_ancestors(&'w self, entity: Entity) -> AncestorIter<'w, 's, D, F> ⓘ
Returns an Iterator
of Entity
s over all of entity
s ancestors.
Can only be called on a Query
of Parent
(i.e. Query<&Parent>
).
§Examples
fn system(query: Query<Entity, With<Marker>>, parent_query: Query<&Parent>) {
let entity = query.single();
for ancestor in parent_query.iter_ancestors(entity) {
// Do something!
}
}