-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Description
What problem does this solve or what need does it fill?
Bevy 0.16 introduced this change: https://bevy.org/learn/migration-guides/0-15-to-0-16/#flush-commands-after-every-mutation-in-worldentitymut,
which causes commands to be flushed at entity or component modifications.
bevy_mod_scripting
uses commands as a way of allowing users to execute callbacks on their scripts, which can arbitrarily affect &mut World
including spawn/despawn entities, or add/remove components.
One thing these commands can also do is potentially queue other callback commands, which are expected to run only once the first callback is completed (because callbacks necessitate removing some resources from the world)
What this change means for BMS is the potential of a callback to run early if a script adds an entity, causing errors.
Ideally It should be possible for my callback runner to "capture" or "freeze" any new commands from executing until it itself completes.
What solution would you like?
Either:
- Command capture mechanism, i.e.
Commands::set_queue
, which lets us push commands to a different queue (perhaps in a function scope to avoid gutting commands generally), and thenCommands::append
that queue when ready - Or
Commands::freeze
which sets a flag that prevents commands from applying for the duration that freeze is set
But the two above don't let me "ignore" the entity commands, so that they can be flushed immediately, but then defer other commands (without some sort of filterin)
Maybe the simplest solution would be not flushing commands other than those necessary for EntityRefMut
to work, mine (perhaps naive) assumption is that commands only ever get applied at ApplyDeferred
sync points.
What alternative(s) have you considered?
I could:
- pull out those resources into Arcs, and lock on every access, which doesn't require changes in Bevy
- Make the command "retry" itself if it knows the handler state is missing, which could have false positives
Additional context
Example reproduction repo from a user facing this problem: https://github.com/Peepo-Juice/bevy_mod_min_repro
With the problem being seen here: