-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Commands queued by component hooks are not applied during exclusive world access #16034
Copy link
Copy link
Closed
Labels
A-ECSEntities, components, systems, and eventsEntities, components, systems, and eventsC-BugAn unexpected or incorrect behaviorAn unexpected or incorrect behaviorD-ComplexQuite challenging from either a design or technical perspective. Ask for help!Quite 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 accomplishedThis issue requires design work to think about how it would best be accomplished
Milestone
Metadata
Metadata
Assignees
Labels
A-ECSEntities, components, systems, and eventsEntities, components, systems, and eventsC-BugAn unexpected or incorrect behaviorAn unexpected or incorrect behaviorD-ComplexQuite challenging from either a design or technical perspective. Ask for help!Quite 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 accomplishedThis issue requires design work to think about how it would best be accomplished
Problem
When an entity is spawned (or other structural changes occur) as part of exclusive world access, commands to apply changes via hooks are generated, but are not immediately applied.
In order to apply these commands, we must call
world.flush, as demonstrated here.This allows users to accidentally observe the state of the world before component lifecycle hooks are applied, but only when working with exclusive world access. As a result, we must be extremely careful if we are relying on hooks for soundness.
Bevy version
0.14.1
Additional context
This is related to #14621, but is intended as a clearer demonstration of a specific problem.
#12235 may end up being blocked on this, as otherwise we could get UB by calling unsafe code on an invalid entity hierarchy.