Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

State can't be used in two stages at once (even with get_driver) #1865

Closed
concave-sphere opened this issue Apr 10, 2021 · 7 comments
Closed
Labels
A-ECS Entities, components, systems, and events C-Bug An unexpected or incorrect behavior S-Needs-Design-Doc This issue or PR is particularly complex, and needs an approved design doc before it can be merged

Comments

@concave-sphere
Copy link

Bevy version

0.5

Operating system & version

Debian GNU/Linux "buster"

What you did

  1. Invoke app.add_state(MyState::StateOne)
  2. Create a stage MyStage
  3. Invoke app.add_system_set(State::<MyState>::get_driver())
  4. Add some systems to MyStage via SystemSet::on_update(MyState::StateOne), etc.
  5. Add a system that switches between states.

What you expected to happen

Systems that trigger on state enter and exit should run when the state changes, regardless of stage.

What actually happened

Only state change systems in the Update stage are executed.

I know that the program hasn't completely locked because if I put state change systems into Update, they work fine. It does lock if I don't add State::<MyState>::get_driver(), so that's having an effect.

This text in the Bevy Rustdoc made me think this is supposed to work:

If you need to use your state in a different stage, consider using Self::add_state_to_stage or manually adding State::get_driver to additional stages you need it in.

Additional information

Sample code:
test.tar.gz

@alice-i-cecile alice-i-cecile added A-Core Common functionality for all bevy apps A-ECS Entities, components, systems, and events C-Bug An unexpected or incorrect behavior labels Apr 10, 2021
@alice-i-cecile
Copy link
Member

Currently, States are owned by Stages, like all other run_criteria :( This should be fixed as part of the grand effort in #1375.

@Ixentus
Copy link
Contributor

Ixentus commented Apr 10, 2021

Instead of app.add_system_set(State::<MyState>::get_driver()) you need add_state_to_stage(MyStage, MyState::StateOne). Internally it does get_driver(), but adds it to the stage.

@concave-sphere
Copy link
Author

Instead of app.add_system_set(State::<MyState>::get_driver()) you need add_state_to_stage(MyStage, MyState::StateOne). Internally it does get_driver(), but adds it to the stage.

I tried replacing

.add_system_set_to_stage(MyStage, State::<MyState>::get_driver())

with

.add_state_to_stage(MyStage, MyState::StateOne)

The behavior I see is exactly the same: only the systems in the Update stage are executed on state transitions.

As a workaround, I've modified the actual code I was working on to just pull in the State resource and check for state transitions by hand (by storing the last-seen state).

@nicopap
Copy link
Contributor

nicopap commented Nov 18, 2021

This is a major issue for me. I'd be happy to contribute a fix.

@cart
Copy link
Member

cart commented Nov 18, 2021

Pulling in @TheRawMeatball (author of the current state system). I recommend discussing alternative designs with them.

@alice-i-cecile alice-i-cecile added S-Needs-Design-Doc This issue or PR is particularly complex, and needs an approved design doc before it can be merged and removed A-Core Common functionality for all bevy apps labels Dec 12, 2021
@alice-i-cecile
Copy link
Member

alice-i-cecile commented Dec 12, 2021

More discussion is roughly centralized in #2801. The existing run-criteria based states are deeply limited and a full redesign is needed.

@alice-i-cecile
Copy link
Member

Fixed by #7267.

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-Bug An unexpected or incorrect behavior S-Needs-Design-Doc This issue or PR is particularly complex, and needs an approved design doc before it can be merged
Projects
Archived in project
Development

No branches or pull requests

5 participants