Expand description
Parent-child relationships for Bevy entities.
You should use the tools in this crate whenever you want to organize your entities in a hierarchical fashion, to make groups of entities more manageable, or to propagate properties throughout the entity hierarchy.
This crate introduces various tools, including a plugin
for managing parent-child relationships between entities.
It provides two components, Parent and Children,
to store references to related entities.
It also provides command and world API extensions
to set and clear those relationships.
More advanced users may also appreciate query extension methods to traverse hierarchies, and events to notify hierarchical changes. There is also a diagnostic plugin to validate property propagation.
§Hierarchy management
The methods defined in this crate fully manage the components responsible for defining the entity hierarchy. Mutating these components manually may result in hierarchy invalidation.
Hierarchical relationships are always managed symmetrically. For example, assigning a child to an entity will always set the parent in the other, and vice versa. Similarly, unassigning a child in the parent will always unassign the parent in the child.
§Despawning entities
The commands and methods provided by bevy_ecs to despawn entities
are not capable of automatically despawning hierarchies of entities.
In most cases, these operations will invalidate the hierarchy.
Instead, you should use the provided hierarchical despawn extension methods.
Modules§
- prelude
- The hierarchy prelude.
Structs§
- AddChild
- Command that adds a child to an entity.
- AddChildren
- Command that pushes children to the end of the entity’s
Children. - Ancestor
Iter - An
IteratorofEntitys over the ancestors of anEntity. - Child
Builder - Struct for building children entities and adding them to a parent entity.
- Children
- Contains references to the child entities of this entity.
- Clear
Children - Command that clears all children from an entity and removes
Parentcomponent from those children. - Descendant
Depth First Iter - An
IteratorofEntitys over the descendants of anEntity. - Descendant
Iter - An
IteratorofEntitys over the descendants of anEntity. - Despawn
Children Recursive - Despawns the given entity’s children recursively
- Despawn
Recursive - Despawns the given entity and all its children recursively
- Hierarchy
Plugin bevy_app - Provides hierarchy functionality to a Bevy app.
- Insert
Children - Command that inserts a child at a given index of a parent’s children, shifting following children back.
- Parent
- Holds a reference to the parent entity of this entity. This component should only be present on entities that actually have a parent entity.
- Remove
Children - Command that removes children from an entity, and removes these children’s parent.
- Remove
Parent - Command that removes the parent of an entity, and removes that entity from the parent’s
Children. - Replace
Children - Command that clear all children from an entity, replacing them with the given children.
- Report
Hierarchy Issue - When enabled, runs
check_hierarchy_component_has_valid_parent<T>. - Valid
Parent Check Plugin - Print a warning for each
Entitywith aTcomponent whose parent doesn’t have aTcomponent. - World
Child Builder - Struct for adding children to an entity directly through the
Worldfor use in exclusive systems.
Enums§
- Hierarchy
Event - An
Eventthat is fired whenever there is a change in the world’s hierarchy.
Traits§
- Build
Children - Trait for removing, adding and replacing children and parents of an entity.
- Child
Build - Trait for building children entities and adding them to a parent entity. This is used in
implementations of
BuildChildrenas a bound on theBuilderassociated type. The closure passed toBuildChildren::with_childrenaccepts an implementation ofChildBuildso that children can be spawned viaChildBuild::spawn. - Despawn
Recursive Ext - Trait that holds functions for despawning recursively down the transform hierarchy
- Hierarchy
Query Ext - An extension trait for
Querythat adds hierarchy related methods.
Functions§
- check_
hierarchy_ component_ has_ valid_ parent bevy_app - System to print a warning for each
Entitywith aTcomponent which parent hasn’t aTcomponent. - despawn_
with_ children_ recursive - Function for despawning an entity and all its children
- on_
hierarchy_ reports_ enabled - Run criteria that only allows running when
ReportHierarchyIssue<T>is enabled.