Allow state.push
with the same state that the app is in
#4542
Labels
A-ECS
Entities, components, systems, and events
C-Usability
A targeted quality-of-life change that makes Bevy easier to use
What problem does this solve or what need does it fill?
Currently, calling
state.push
on a state that the app is currently in yields anErr(StateError::AlreadyInState)
. This is a problem for devs who want to stack multiple states of the same variant. In my case, I have aGameState::Menu
state that I want to stack directly on top of each other, since I have menus that lead to other menus. I haveon_enter
andon_exit
systems that I want to run for each of my menus. My menus are determined at runtime, so I cannot add a newGameState
variant for every menu in the game. My current workaround involves adding aGameState::Buffer
between eachGameState::Menu
. MyGameState::Buffer
immediately pushes a given state inon_enter
, and immediately pops inon_resume
. Removing the error fromstate.push
would let me remove this workaround and help to clean up my game's logic.What solution would you like?
I would like the
return Err(StateError::AlreadyInState);
statement to be removed fromstate.push
What alternative(s) have you considered?
GameState::Buffer
between eachGameState::Menu
to work around the issue, as described abovestate.push
should check the entire stack to make sure that there are no duplicates. Then, I could run the logic that I have inon_enter
andon_exit
manually instead, or use events.The text was updated successfully, but these errors were encountered: