|  | 
|  | 1 | +--- | 
|  | 2 | +title: Generic component propagation | 
|  | 3 | +authors: ["@robtfm"] | 
|  | 4 | +pull_requests: [17575] | 
|  | 5 | +--- | 
|  | 6 | + | 
|  | 7 | +When working with large hierarchies of game objects, coordinating the state of the entire tree can be frustrating. | 
|  | 8 | +Bevy uses this pattern when working with transforms and visibility internally, | 
|  | 9 | +but users have had to reinvent the wheel every time they wanted to use similar patterns. | 
|  | 10 | + | 
|  | 11 | +While this pain was most acute when working with [`RenderLayers`], this pattern is more broadly useful, | 
|  | 12 | +and has been exposed to end users in the form of the [`HierarchyPropagatePlugin`]. | 
|  | 13 | +You might use this for synchronizing color and alpha values for "ghost" versions of previewed buildings, | 
|  | 14 | +ensuring that all of the parts of a model are on the same render layer, | 
|  | 15 | +or propagating font styles. | 
|  | 16 | + | 
|  | 17 | +This plugin has three generics: | 
|  | 18 | + | 
|  | 19 | +- `C: Component`: the type of component that should be propagated | 
|  | 20 | +- `F: QueryFilter=()`: if set, only entities which match this filter will be affected by propagation | 
|  | 21 | +- `R: Relationship = ChildOf`: the type of tree-like relationship to propagate down | 
|  | 22 | + | 
|  | 23 | +Each copy of this plugin will propagate components of type `C` down the hierarchy, along all entities which match the | 
|  | 24 | +query filter of type `F`. | 
|  | 25 | +With this plugin enabled for `C`, you can add a [`Propagate<C>`] component to add new components to all children, | 
|  | 26 | +add a [`PropagateStop<C>`] component to stop propagation, or even use [`PropagateOver<C>`] to skip this entity during propagation. | 
|  | 27 | + | 
|  | 28 | +This is a very general tool: please let us know what you're using it for and we can continue to add examples to the docs! | 
|  | 29 | + | 
|  | 30 | +[`RenderLayers`]: https://dev-docs.bevy.org/bevy/camera/visibility/struct.RenderLayers.html | 
|  | 31 | +[`HierarchyPropagatePlugin`]: https://dev-docs.bevy.org/bevy/app/struct.HierarchyPropagatePlugin.html | 
|  | 32 | +[`Propagate<C>`]: https://dev-docs.bevy.org/bevy/app/struct.Propagate.html | 
|  | 33 | +[`PropagateStop<C>`]: https://dev-docs.bevy.org/bevy/app/struct.PropagateStop.html | 
|  | 34 | +[`PropagateOver<C>`]: https://dev-docs.bevy.org/bevy/app/struct.PropagateOver.html | 
0 commit comments