Skip to content

Removing Parent / Children from the world and then reinserting them can break hierarchies #15575

@alice-i-cecile

Description

@alice-i-cecile

Problem

Within the internals of the transform propagation systems, we rely on hierarchies being well-formed (via #4197) for soundness, and panic if they are not in this line. This was added in #4775.

This is why we haven't added simple constructors or mutable access to Parent or Children (like Clone or Copy), like in #15574. If we can ever swap or set the value of Parent or Children directly, it becomes very easy to break the hierarchy. Unfortunately, this isn't the only way to get that problem.

Path 1: get mutable access to two different components via Query::get_many_mut or the like, and then mem_swap them.

Path 2: remove Parent / Children from an entity via a method on World that returns the removed value

Potential solutions

  1. Wait for Entity-entity relations 🌈  #3742.
  2. Implement Use component lifecycle hooks to make Parent + Children hierarchy code simpler and more robust #12235 in an airtight way.
  3. Make bevy_transform fully safe and eat the performance hit and correctness problems if people break their hierarchy by mistake.
  4. Add more, niche, high complexity features to absolutely forbid mutable access to some component types. Somehow.

I prefer 2, and would be opposed to both 3 and 4.

Additional context

Because this is actually guarded against by an assert, I think that merging #15574's successor is actually fine (cc @atornity, sorry).

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-ECSEntities, components, systems, and eventsA-TransformTranslations, rotations and scalesC-BugAn unexpected or incorrect behaviorD-ComplexQuite challenging from either a design or technical perspective. Ask for help!S-Needs-DesignThis issue requires design work to think about how it would best be accomplishedX-ControversialThere is active debate or serious implications around merging this PR

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions