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:
TheBigCheese 2024-09-30 18:23:52 +01:00 committed by GitHub
parent 04d5685889
commit dd92a7705d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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() } {