Skip to content

Add a way to refer back to a common deep ancestor 🦑#5534

Closed
nicopap wants to merge 1 commit intobevyengine:mainfrom
nicopap:ancestor-reference-generator
Closed

Add a way to refer back to a common deep ancestor 🦑#5534
nicopap wants to merge 1 commit intobevyengine:mainfrom
nicopap:ancestor-reference-generator

Conversation

@nicopap
Copy link
Contributor

@nicopap nicopap commented Aug 1, 2022

Objective

This allows querying for a potentially far-off ancestor in the bevy
hierarchy with the Ancestor component.

Motivation

I found myself needing such components a lot in #5378,
I think it might also have a few other applications.

Solution

It's a very simple system that recursively traverse the children of an
entity marked with a MarkDescendants component, and adds a Ancestor
component to entities that comply to a rule provided in the
MarkDescendants component.

drawbacks:

  • It is not "smart", it's just a one-off event that generates the
    components once. No dynamically updating the Ancestor component
    to account for runtime changes to the hierarchy.
  • It requires an exclusive system. An alternative design could be
    providing a generic system and letting the user add the system with
    their prefered query filter.
  • Users need to add the mark_descendants system themselves.

Changelog

  • Added the MarkDescendants and Ancestor components to make deep hierarchical relations easier to handle

@nicopap nicopap added C-Feature A new feature, making something new possible A-Hierarchy labels Aug 1, 2022
@nicopap nicopap marked this pull request as draft August 1, 2022 16:59
@nicopap nicopap force-pushed the ancestor-reference-generator branch 2 times, most recently from c7965e8 to 33b0a4b Compare August 18, 2022 12:03
bors bot added a commit that referenced this pull request Aug 18, 2022
@bors
Copy link
Contributor

bors bot commented Aug 18, 2022

try

Build failed:

@nicopap
Copy link
Contributor Author

nicopap commented Aug 19, 2022

bors try

bors bot added a commit that referenced this pull request Aug 19, 2022
@nicopap nicopap force-pushed the ancestor-reference-generator branch from 33b0a4b to e514c80 Compare August 19, 2022 08:39
This allows querying for a potentially far-off ancestor in the bevy
hierarchy with the `Ancestor` component.

It's a very simple system that recursively traverse the children of an
entity marked with a `MarkDescendants` component, and adds a `Ancestor`
component to entities that comply to a rule provided in the
`MarkDescendants` component.

drawbacks:
- It is not "smart", it's just a one-off event that generates the
  components once. No dynamically updating the `Ancestor` component
  to account for runtime changes to the hierarchy.
- It requires an exclusive system. An alternative design could be
  providing a generic system and letting the user add the system with
  their prefered query filter.
- Users need to add the `mark_descendants` system themselves.
@nicopap nicopap force-pushed the ancestor-reference-generator branch from e514c80 to f4e4d42 Compare August 19, 2022 08:47
@nicopap nicopap marked this pull request as ready for review August 19, 2022 08:51
@nicopap nicopap closed this Jan 23, 2023
@alice-i-cecile alice-i-cecile added A-ECS Entities, components, systems, and events and removed A-Hierarchy 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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants