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

Running systems with both a state and a stage limitation causes systems to sometimes just be ignored. #3870

Closed
haihala opened this issue Feb 5, 2022 · 3 comments
Labels
A-ECS Entities, components, systems, and events C-Bug An unexpected or incorrect behavior

Comments

@haihala
Copy link

haihala commented Feb 5, 2022

Bevy version

0.6 off of crates.io

Operating system & version

Windows 10.

What you did

  1. Wanted to make system execution order (more) deterministic.
  2. Did this by assigning systems to stages with app.add_system_to_stage
  3. Got a white screen and the program froze on load with the warning WARN bevy_ecs::schedule::graph_utils: Chain(bevy_ecs::schedule::state::State<time::game_flow::GameState>::on_enter::{{closure}}, bevy_ecs::schedule::state::should_run_adapter<time::game_flow::GameState>) wants to be after unknown label: DriverLabel(TypeId { t: 3089577881103655877 })
  4. Added a driver system set (don't understand how this works at all) with app.add_system_set_to_stage(CoreState::First, State::<my custom state enum>::get_driver())
  5. That worked for CoreState::First
  6. Want to do the same for CoreState::Last with state run criteria, repeat 3-4 for the new stage
  7. Doesn't crash, but the run criteria never passes. Removing the run criteria the system runs every tick (want it to run on entry to a state)
  8. Switched order of ...::get_driver() commands,
  9. Systems in CoreStage::Last work, systems in CoreStage::First with run_criteria don't

What you expected to happen

Expected all systems to run

What actually happened

Systems get executed based on the order of the added stages. Only impacts systems with further run criteria and doesn't impact ones that always run in a stage.

Additional information

Snippet from the plugin that adds the state:

        .add_state(GameState::PreRound)
        .add_system_set_to_stage(CoreStage::Last, State::<GameState>::get_driver())
        .add_system_set_to_stage(CoreStage::First, State::<GameState>::get_driver())

Usage:

        .add_system_to_stage(
            CoreStage::First,
            update_clock
                .with_run_criteria(FixedTimestep::steps_per_second(constants::FPS as f64))
                .label(TimeSystemLabel::UpdateClock),
        )
        ...
        .add_system_to_stage(
            CoreStage::Last,
            text::update_timer
                .with_run_criteria(State::on_update(GameState::Combat))
                .label(UISystemLabel::Timer),
        )
@haihala haihala added C-Bug An unexpected or incorrect behavior S-Needs-Triage This issue needs to be labelled labels Feb 5, 2022
@haihala
Copy link
Author

haihala commented Feb 5, 2022

Can't say I still understand how it works, but I added the state to some more stages and changed from app.add_state to app.add_state_to_stage and now State::on_update seems to work, while State::on_enter doesn't. I can work with this, although I'd really wish for an explanation.

@alice-i-cecile alice-i-cecile added A-ECS Entities, components, systems, and events and removed S-Needs-Triage This issue needs to be labelled labels Feb 6, 2022
@alice-i-cecile
Copy link
Member

Thank you for the thorough writeup!

States that work across multiple stages are very much a fragile hack, so I'm unsurprised that this broke in surprising ways. I think that the reason the on-enter doesn't work properly is because the state already decides that entry is complete at the end of the first stage that it has been entered in.

This will almost certainly just be fixed / obsoleted by the stageless redesign: bevyengine/rfcs#45.

@haihala
Copy link
Author

haihala commented Feb 9, 2022

Awesome thanks

@haihala haihala closed this as completed Feb 9, 2022
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
Projects
None yet
Development

No branches or pull requests

2 participants