bevyengine / bevyengine/bevy

Add more tools to conveniently work with hierarchies, especially in the presence of ghost nodes

Open
#15,609 6 comments 0 reactions 0 assignees View on GitHub
A-UI C-Feature D-Modest S-Ready-For-Implementation
Dominant language
Rust
Stars
48.2k
Forks
4.8k
Avg merge
3d 22h
Merged PRs (30d)
161

Description

## What problem does this solve or what need does it fill?

Following the introduction of https://github.com/bevyengine/bevy/pull/15341, some users have expressed concerns around difficulties migrating to account for ghost nodes in their hierarchies.

This is a great opportunity to add more tools for traversing hierarchies in the spirit of [`iter_descendants`](https://docs.rs/bevy/latest/bevy/hierarchy/trait.HierarchyQueryExt.html#tymethod.iter_descendants).

## What solution would you like?

There are two stages to this:

1. Add more methods to `HierarchyQueryExt` to capture other common tasks.
2. Add a ghost-node aware version of this trait, which lives in `bevy_ui` and takes a `Has` argument as well. These methods should be named `iter_node_descendants` and so on.

In theory these can be done in either order, or in a single PR. Your choice!

In terms of additional tasks to cover:

1. `root_parent`: the entity that is highest up the hierarchy tree, if any.
2. `leaf_children`: an iterator over the children that have no children of their own.
3. `siblings`: other entities that are in direct children of the same parent.
4. `parent`: a convenience method that looks for the parent (much more useful when working with ghost nodes).
5. `children`: as above, but for children.

## What alternative(s) have you considered?

One day (🥺), this will get rolled into #3742. It's nice to ship helpful APIs to users sooner though, and these methods will be easier to migrate since they have semantic meaning.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.