mirror of
https://github.com/bevyengine/bevy
synced 2024-11-21 20:23:28 +00:00
Small addition to World::flush_commands
explaining how spawn
will cause it to panic. (#15411)
# Objective `World::flush_commands` will cause a panic with `error[B0003]: Could not insert a bundle [...] for entity [...] because it doesn't exist in this World` if there was a `spawn` command in the queue and you should instead use `flush` for this but this isn't mentioned in the docs ## Solution Add a note to the docs suggesting to use `World::flush` in this context. This error doesn't appear to happen with `spawn_batch` so I didn't add that to the note although you can cause it with `commands.spawn_empty().insert(...)` but I wasn't sure that was worth the documentation complexity as it is pretty unlikely (and equivalent to `commands.spawn(...)`.
This commit is contained in:
parent
04d5685889
commit
dd92a7705d
1 changed files with 3 additions and 0 deletions
|
@ -2226,6 +2226,9 @@ impl World {
|
|||
|
||||
/// Applies any commands in the world's internal [`CommandQueue`].
|
||||
/// This does not apply commands from any systems, only those stored in the world.
|
||||
///
|
||||
/// This will panic if any of the queued commands are [`spawn`](Commands::spawn).
|
||||
/// If this is possible, you should instead use [`flush`](Self::flush).
|
||||
pub fn flush_commands(&mut self) {
|
||||
// SAFETY: `self.command_queue` is only de-allocated in `World`'s `Drop`
|
||||
if !unsafe { self.command_queue.is_empty() } {
|
||||
|
|
Loading…
Reference in a new issue