Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

generic component propagation #17575

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Conversation

robtfm
Copy link
Contributor

@robtfm robtfm commented Jan 28, 2025

Objective

add functionality to allow propagating components to children. requested originally for RenderLayers but can be useful more generally.

Solution

  • add HierarchyPropagatePlugin<C, F=()> which schedules systems to propagate components through entities matching F
  • add Propagate<C: Component + Clone + PartialEq> which will cause C to be added to all children
    more niche features:
  • add PropagateStop<C> which stops the propagation at this entity
  • add PropagateOver<C> which allows the propagation to continue to children, but doesn't add/remove/modify a C on this entity itself

Testing

see tests inline

Notes

  • could happily be an out-of-repo plugin
  • not sure where it lives: ideally it would be in bevy_ecs but it requires a Plugin so I put it in bevy_app, doesn't really belong there though.
  • i'm not totally up-to-date on triggers and observers so possibly this could be done more cleanly, would be very happy to take review comments
  • perf: this is pretty cheap except for update_reparented which has to check the parent of every moved entity. since the entirety is opt-in i think it's acceptable but i could possibly use (Changed<Children>, With<Inherited<C>>) instead if it's a concern

@IceSentry IceSentry added C-Feature A new feature, making something new possible A-ECS Entities, components, systems, and events C-Usability A targeted quality-of-life change that makes Bevy easier to use S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Jan 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ECS Entities, components, systems, and events C-Feature A new feature, making something new possible C-Usability A targeted quality-of-life change that makes Bevy easier to use S-Needs-Review Needs reviewer attention (from anyone!) to move forward
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants