#How to add startup system after I change my game state?

12 messages · Page 1 of 1 (latest)

topaz raptor
#

Basically I start my game in a GameState::Loading and after everything is loaded I change to GameState::Login, but I want to render some UI components here in a startup system (I'm not sure if this is the right way to do it), but when I change my state to GameState::Login I receive a warning and nothing renders

App::new()
        .add_plugins(DefaultPlugins.set(WindowPlugin {
            window: WindowDescriptor {
                title: String::from("Game"),
                mode: WindowMode::BorderlessFullscreen,
                ..Default::default()
            },
            ..Default::default()
        }))
        .add_plugin(WorldInspectorPlugin::default())
        .add_state(GameState::Loading)
        .add_startup_system(load_assets)
        .add_startup_system(loading_ui)
        .add_startup_system(connect_to_server)
        .add_system_set(SystemSet::on_enter(GameState::Loading).with_system(check_assets_loaded))
        .add_startup_system_set(SystemSet::on_enter(GameState::Login).with_system(login_ui))
        .run();

And the warning that I get:

WARN bevy_ecs::schedule::graph_utils: Pipe(bevy_ecs::schedule::state::State<client::state::GameState>::on_enter::{{closure}}, bevy_ecs::schedule::state::should_run_adapter<client::state::GameState>) wants to be after unknown label: client::state::GameState
tawdry minnow
#

Startup systems run once when your app starts

#

You should change that to a regular add_system_set

topaz raptor
#

so how do I run a system that only renders some UI without making it spawn the same stuff on every render?

#
pub fn login_ui(mut commands: Commands, asset_server: Res<AssetServer>) {
    commands.spawn(Camera2dBundle::default());
    commands.spawn((
        // Create a TextBundle that has a Text with a single section.
        TextBundle::from_section(
            // Accepts a `String` or any type that converts into a `String`, such as `&str`
            "LOGIN",
            TextStyle {
                font: asset_server.load("fonts/roboto.ttf"),
                font_size: 100.0,
                color: Color::WHITE,
            },
        ) // Set the alignment of the Text
        .with_text_alignment(TextAlignment::TOP_CENTER)
        // Set the style of the TextBundle itself.
        .with_style(Style {
            position_type: PositionType::Absolute,
            position: UiRect {
                bottom: Val::Px(5.0),
                right: Val::Px(15.0),
                ..default()
            },
            ..default()
        }),
    ));
}
tawdry minnow
#

Exactly like you have it pretty much haha. A state’s on_enter only runs once as soon as you enter that state

topaz raptor
#

oh, cool, I didn't know it would only run once after the on enter, thanks!

tawdry minnow
#

Yep super handy! Same goes for on_exit

#

You can use those two to “act like startup systems”

topaz raptor
#

I believe I should use the on_exit to remove the UI stuff that I don't want to show anymore, right?

tawdry minnow
#

Yeah I’d think so

haughty sable
#

there are dragons to contend with if you want to do certain things like changing state, have multiple ordered startup systems that need feedback from prerequisite commands