Skip to content

Small addition to World::flush_commands explaining how spawn will cause it to panic.#15411

Merged
alice-i-cecile merged 2 commits intobevyengine:mainfrom
13ros27:flush_commands_docs
Sep 30, 2024
Merged

Small addition to World::flush_commands explaining how spawn will cause it to panic.#15411
alice-i-cecile merged 2 commits intobevyengine:mainfrom
13ros27:flush_commands_docs

Conversation

@13ros27
Copy link
Copy Markdown
Contributor

@13ros27 13ros27 commented Sep 24, 2024

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(...).

@SkiFire13
Copy link
Copy Markdown
Contributor

Is there a situation where you would want to call flush_commands instead of flush? If not then it might be made private to avoid potential confusions or misuses.

@13ros27
Copy link
Copy Markdown
Contributor Author

13ros27 commented Sep 24, 2024

I was wondering that when I noticed flush was a method after getting confused by the panic, I'm not sure, the only difference is that flush_commands doesn't deal with reserved entities

@pablo-lua pablo-lua added C-Docs An addition or correction to our documentation A-ECS Entities, components, systems, and events D-Straightforward Simple bug fixes and API improvements, docs, test and examples S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Sep 24, 2024
@pablo-lua pablo-lua added S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it and removed S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Sep 25, 2024
@alice-i-cecile alice-i-cecile added this pull request to the merge queue Sep 30, 2024
Merged via the queue into bevyengine:main with commit dd92a77 Sep 30, 2024
robtfm pushed a commit to robtfm/bevy that referenced this pull request Oct 4, 2024
… cause it to panic. (bevyengine#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(...)`.
@13ros27 13ros27 deleted the flush_commands_docs branch October 4, 2024 10:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-ECS Entities, components, systems, and events C-Docs An addition or correction to our documentation D-Straightforward Simple bug fixes and API improvements, docs, test and examples S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants