bevy/release-content/migration-guides/observers_may_not_be_exclusive.md
Chris Russell 5f936aefc8
Prevent exclusive systems from being used as observers (#19033)
# Objective

Prevent using exclusive systems as observers. Allowing them is unsound,
because observers are only expected to have `DeferredWorld` access, and
the observer infrastructure will keep pointers that are invalidated by
the creation of `&mut World`.

See
https://github.com/bevyengine/bevy/actions/runs/14778342801/job/41491517847?pr=19011
for a MIRI failure in a recent PR caused by an exclusive system being
used as an observer in a test.

## Solution

Have `Observer::new` panic if `System::is_exclusive()` is true. Document
that method, and methods that call it, as panicking.

(It should be possible to express this in the type system so that the
calls won't even compile, but I did not want to attempt that.)

## Testing

Added a unit test that calls `World::add_observer` with an exclusive
system.
2025-05-05 17:46:25 +00:00

422 B

title pull_requests
Exclusive systems may not be used as observers
19033

Exclusive systems may no longer be used as observers. This was never sound, as the engine keeps references alive during observer invocation that would be invalidated by &mut World access, but was accidentally allowed. Instead of &mut World, use either DeferredWorld if you do not need structural changes, or Commands if you do.