#Bevy Resource does not exist for some reason

26 messages · Page 1 of 1 (latest)

sharp garnet
#
    App::new()
        .add_plugins(DefaultPlugins)
        // Insert as resource the initial value for the settings resources
        .insert_resource(menumanager::DisplayQuality::Medium)
        .insert_resource(menumanager::Volume(7))

        // Declare the game state, whose starting value is determined by the `Default` trait //Entering splash first
        .init_state::<menumanager::GameState>()
        //Startup
        .add_systems(PreStartup, (setup,textstyle::load_fonts))
        // Adds the plugins for each state
        //menumanager
        .add_plugins((menumanager::splash::splash_plugin, menumanager::menu::menu_plugin, menumanager::game::game_plugin))
        .run();
}``` This is the main function where load_fonts creates a Resource and the splash plugin uses it. But for some reason the resource doesnt exist when splash uses it
elfin dove
#

What does the error message say? And how is the resource being used exactly?

sharp garnet
#
Resource requested by circuit0::menumanager::splash::splash_setup does not exist: circuit0::textstyle::FontECS
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Encountered a panic in system `circuit0::menumanager::splash::splash_setup`!
Encountered a panic in system `Pipe(bevy_state::state::transitions::last_transition<circuit0::menumanager::GameState>, bevy_state::state::transitions::run_enter<circuit0::menumanager::GameState>)`!
Encountered a panic in system `bevy_app::main_schedule::Main:
:run_main`!```
#

the error

#

Used in this function:

#

        // Insert the timer as a resource (did 0.0 to skip splash screen during development)
        commands.insert_resource(SplashTimer(Timer::from_seconds(1.0, TimerMode::Once)));

        let icon = asset_server.load("branding/icon.png");
        // Display the logo
        commands
            .spawn((
                NodeBundle {
                    style: Style {
                        align_items: AlignItems::Center,
                        justify_content: JustifyContent::Center,
                        width: Val::Percent(100.0),
                        height: Val::Percent(100.0),
                        ..default()
                    },
                    ..default()
                },
                OnSplashScreen,
            ))
            .with_children(|parent| {
                parent.spawn(ImageBundle {
                    style: Style {
                        // This will set the logo to be 200px wide, and auto adjust its height
                        width: Val::Px(200.0),
                        ..default()
                    },
                    image: UiImage::new(icon),
                    ..default()
                });
                // Display the Engine name
                parent.spawn(TextBundle::from_section(
                        "Bevy",
                        TextStyle {
                            font_size: 80.0,
                            font: fontecs.fonthandle_1.clone(),
                            color: TEXT_COLOR,
                            ..default()
                        },
                    )
                    .with_style(Style {
                        margin: UiRect::all(Val::Px(50.0)),
                        ..default()
                    })
                );
        });
    }```
elfin dove
#

And how is this system added by the plugin?

sharp garnet
#
    pub fn splash_plugin(app: &mut App) {
        // As this plugin is managing the splash screen, it will focus on the state `GameState::Splash`
        app
            // When entering the state, spawn everything needed for this screen
            .add_systems(OnEnter(GameState::Splash), splash_setup)
            // While in this state, run the `countdown` system
            .add_systems(Update, countdown.run_if(in_state(GameState::Splash)))
            // When exiting the state, despawn everything that was spawned for this screen
            .add_systems(OnExit(GameState::Splash), despawn_screen::<OnSplashScreen>);
    }```
elfin dove
#

Hm my initial guess was ordering issues in startup systems, but you’re using OnEnter. Does that run before the startup system by chance?

sharp garnet
#

the splash gamestate is the default state

#

is that the culprit?

elfin dove
#

It could be but if it is I’m just surprised that it would run before PreStartup

sharp garnet
#

I fixed it by adding a PreSplash Gamestate

#

It did indeed run before PreStartup

elfin dove
#

Strange

#

Might be worth raising in #ecs-dev

sharp garnet
#

how do I do that

#

I am nowhere near qualified to issue a bug 😂

elfin dove
#

You can just pop in and ask them if they’ve seen this before (there could also just be something I’m completely missing here haha). They’ll have more insight than me

elfin dove
dawn fiber
#

Id need to remins myself how current initial transition works, but thats very much plausible

#

One of the goals was to "always be in a valid state" meaning state enter schedules ran before any startup

dawn fiber
#

there was even a whole discussion that we should remove "startup" and rely on state transitions instead

elfin dove
#

So it’s possible this is more of a documentation issue?

dawn fiber