Component hooks are not applied during exclusive world access #16034
Labels
A-ECS
Entities, components, systems, and events
C-Bug
An unexpected or incorrect behavior
D-Complex
Quite challenging from either a design or technical perspective. Ask for help!
S-Needs-Design
This 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.
The text was updated successfully, but these errors were encountered: