Skip to content

Allow state.push with the same state that the app is in #4542

@Seldom-SE

Description

@Seldom-SE

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 an Err(StateError::AlreadyInState). This is a problem for devs who want to stack multiple states of the same variant. In my case, I have a GameState::Menu state that I want to stack directly on top of each other, since I have menus that lead to other menus. I have on_enter and on_exit systems that I want to run for each of my menus. My menus are determined at runtime, so I cannot add a new GameState variant for every menu in the game. My current workaround involves adding a GameState::Buffer between each GameState::Menu. My GameState::Buffer immediately pushes a given state in on_enter, and immediately pops in on_resume. Removing the error from state.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 from state.push

What alternative(s) have you considered?

  • I am currently adding a GameState::Buffer between each GameState::Menu to work around the issue, as described above
  • If duplicate states are not supposed to be allowed in the stack, then state.push should check the entire stack to make sure that there are no duplicates. Then, I could run the logic that I have in on_enter and on_exit manually instead, or use events.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-ECSEntities, components, systems, and eventsC-UsabilityA targeted quality-of-life change that makes Bevy easier to use

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions