bevy_hierarchy

Trait HierarchyQueryExt

Source
pub trait HierarchyQueryExt<'w, 's, D: QueryData, F: QueryFilter> {
    // Required methods
    fn parent(&'w self, entity: Entity) -> Option<Entity>
       where D::ReadOnly: WorldQuery<Item<'w> = &'w Parent>;
    fn children(&'w self, entity: Entity) -> &'w [Entity]
       where D::ReadOnly: WorldQuery<Item<'w> = &'w Children>;
    fn root_ancestor(&'w self, entity: Entity) -> Entity
       where D::ReadOnly: WorldQuery<Item<'w> = &'w Parent>;
    fn iter_leaves(
        &'w self,
        entity: Entity,
    ) -> impl Iterator<Item = Entity> + 'w
       where D::ReadOnly: WorldQuery<Item<'w> = &'w Children>;
    fn iter_siblings(&'w self, entity: Entity) -> impl Iterator<Item = Entity>
       where D::ReadOnly: WorldQuery<Item<'w> = (Option<&'w Parent>, Option<&'w Children>)>;
    fn iter_descendants(
        &'w self,
        entity: Entity,
    ) -> DescendantIter<'w, 's, D, F> 
       where D::ReadOnly: WorldQuery<Item<'w> = &'w Children>;
    fn iter_descendants_depth_first(
        &'w self,
        entity: Entity,
    ) -> DescendantDepthFirstIter<'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 parent(&'w self, entity: Entity) -> Option<Entity>
where D::ReadOnly: WorldQuery<Item<'w> = &'w Parent>,

Returns the parent Entity of the given entity, if any.

Source

fn children(&'w self, entity: Entity) -> &'w [Entity]
where D::ReadOnly: WorldQuery<Item<'w> = &'w Children>,

Returns a slice over the Children of the given entity.

This may be empty if the entity has no children.

Source

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

Returns the topmost ancestor of the given entity.

This may be the entity itself if it has no parent.

Source

fn iter_leaves(&'w self, entity: Entity) -> impl Iterator<Item = Entity> + 'w
where D::ReadOnly: WorldQuery<Item<'w> = &'w Children>,

Returns an Iterator of Entitys over the leaves of the hierarchy that are underneath this entity.

Only entities which have no children are considered leaves. This will not include the entity itself, and will not include any entities which are not descendants of the entity, even if they are leaves in the same hierarchical tree.

Traverses the hierarchy depth-first.

Source

fn iter_siblings(&'w self, entity: Entity) -> impl Iterator<Item = Entity>
where D::ReadOnly: WorldQuery<Item<'w> = (Option<&'w Parent>, Option<&'w Children>)>,

Returns an Iterator of Entitys over the entitys immediate siblings, who share the same parent.

The entity itself is not included in the iterator.

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 and does not include the entity itself.

§Examples
fn system(entity: Single<Entity, With<Marker>>, children_query: Query<&Children>) {
    for descendant in children_query.iter_descendants(*entity) {
        // Do something!
    }
}
Source

fn iter_descendants_depth_first( &'w self, entity: Entity, ) -> DescendantDepthFirstIter<'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>).

This is a depth-first alternative to HierarchyQueryExt::iter_descendants.

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.

Does not include the entity itself. Can only be called on a Query of Parent (i.e. Query<&Parent>).

§Examples
fn system(entity: Single<Entity, With<Marker>>, parent_query: Query<&Parent>) {
    for ancestor in parent_query.iter_ancestors(*entity) {
        // Do something!
    }
}

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

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 parent(&'w self, entity: Entity) -> Option<Entity>
where <D as QueryData>::ReadOnly: WorldQuery<Item<'w> = &'w Parent>,

Source§

fn children(&'w self, entity: Entity) -> &'w [Entity]
where <D as QueryData>::ReadOnly: WorldQuery<Item<'w> = &'w Children>,

Source§

fn root_ancestor(&'w self, entity: Entity) -> Entity
where <D as QueryData>::ReadOnly: WorldQuery<Item<'w> = &'w Parent>,

Source§

fn iter_leaves(&'w self, entity: Entity) -> impl Iterator<Item = Entity>
where <D as QueryData>::ReadOnly: WorldQuery<Item<'w> = &'w Children>,

Source§

fn iter_siblings(&'w self, entity: Entity) -> impl Iterator<Item = Entity>
where D::ReadOnly: WorldQuery<Item<'w> = (Option<&'w Parent>, Option<&'w Children>)>,

Source§

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

Source§

fn iter_descendants_depth_first( &'w self, entity: Entity, ) -> DescendantDepthFirstIter<'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§