Skip to content

Commit f96eaa4

Browse files
Release notes for generic component propagation (#20354)
# Objective Fixes #20143. ## Solution These release notes were adopted from the PR description and docs added in #17575 by @robtfm. When writing these, I've focused on providing context, potential applications, and breaking down the complex generics for newer Bevy users.
1 parent 14d9f6e commit f96eaa4

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

crates/bevy_app/src/propagate.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ use bevy_reflect::Reflect;
3030
/// to reach a given target.
3131
/// Individual entities can be skipped or terminate the propagation with the [`PropagateOver`]
3232
/// and [`PropagateStop`] components.
33+
///
34+
/// Propagation occurs during [`Update`] in the [`PropagateSet<C>`] system set.
35+
/// You should be sure to schedule your logic relative to this set: making changes
36+
/// that modify component values before this logic, and reading the propagated
37+
/// values after it.
3338
pub struct HierarchyPropagatePlugin<
3439
C: Component + Clone + PartialEq,
3540
F: QueryFilter = (),
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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

Comments
 (0)