Skip to content

Observers don't respect the "stack nature" of commands #19569

Open
@Pascualex

Description

@Pascualex

Bevy version

v0.16.1

What you did

Run commands from an observer.

What went wrong

I was expecting those commands to be executed before any other observer, instead several observers ran before the "previous" commands.

The stack nature of commands is critical for certain tasks. In my case, I want to fully solve one collision and its consequences before moving to the next one since I don't want my projectiles to hit more than one target.

Order I expected:

  • Observer 1
    • Command 1 from Observer 1
    • Command 2 from Observer 1
  • Observer 2
    • Command 3 from Observer 2
    • Command 4 from Observer 2

Order I got:

  • Observer 1
  • Observer 2
  • Command 1 from Observer 1
  • Command 2 from Observer 1
  • Command 3 from Observer 2
  • Command 4 from Observer 2

Additional information

It is easy to work around, now my observers only do one thing: run a single one-shot system. This way, all my logic now runs in command-land and the stack works as expected.

Order I have now:

  • Observer 1
  • Observer 2
  • Command A from Observer 1
    • Command 1 from Command A
    • Command 2 from Command A
  • Command B from Observer 2
    • Command 3 from Command B
    • Command 4 from Command B

Maybe this could also be the solution? Making observers insert a command instead of running their system directly?

In my case the consequence was that my game was crashing unexpectedly, since I was triggering new events and despawning entities. When unexpected ordering caused me to trigger an event on a despawned entity, the game crashed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-ECSEntities, components, systems, and eventsC-BugAn unexpected or incorrect behaviorS-Needs-DesignThis issue requires design work to think about how it would best be accomplished

    Type

    No type

    Projects

    Status

    Observer overhaul

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions