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§

source

fn iter_descendants(&'w self, entity: Entity) -> DescendantIter<'w, 's, D, F>
where D::ReadOnly: WorldQuery<Item<'w> = &'w Children>,

Returns an Iterator of Entitys over all of entitys 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!
    }
}
source

fn iter_ancestors(&'w self, entity: Entity) -> AncestorIter<'w, 's, D, F>
where D::ReadOnly: WorldQuery<Item<'w> = &'w Parent>,

Returns an Iterator of Entitys over all of entitys 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!
    }
}

Implementations on Foreign Types§

source§

impl<'w, 's, D: QueryData, F: QueryFilter> HierarchyQueryExt<'w, 's, D, F> for Query<'w, 's, D, F>

source§

fn iter_descendants(&'w self, entity: Entity) -> DescendantIter<'w, 's, D, F>
where D::ReadOnly: WorldQuery<Item<'w> = &'w Children>,

source§

fn iter_ancestors(&'w self, entity: Entity) -> AncestorIter<'w, 's, D, F>
where D::ReadOnly: WorldQuery<Item<'w> = &'w Parent>,

Implementors§