bevyengine / bevyengine/bevy

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

Open
#19,569 7 comments 0 reactions 0 assignees View on GitHub
A-ECS C-Bug D-Complex S-Needs-Design
Dominant language
Rust
Stars
48.2k
Forks
4.8k
Avg merge
3d 16h
Merged PRs (30d)
171

Description

## 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.

Contributor guide

Open the contributing guide

Research direction

No source files or tests are named. Reproduce the observer and command ordering described in the issue on Bevy v0.16.1, then trace the observer scheduling and command-application entry points; done means commands from one observer are processed before the next observer when the stack semantics require it, without the reported crash scenario.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
game-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.