Skip to content

Commands queued by component hooks are not applied during exclusive world access #16034

@alice-i-cecile

Description

@alice-i-cecile

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-ECSEntities, components, systems, and eventsC-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 accomplished

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions