-
I’m not sure whether it’s something I’m doing wrong or an actual bug. I have the following system: impl NanpurePlugin {
fn setup(
mut commands: Commands,
assets: Res<AssetServer>,
) -> Result {
let easy_mode: EasyMode = false.into();
commands.insert_resource(ClearColor(BACKGROUND_COLOR));
commands.insert_resource(easy_mode);
commands.insert_resource(TitleFont::new(&assets)?);
Ok(())
}
} And another system that uses that impl MainMenu {
pub fn spawn(
mut commands: Commands,
font: Res<TitleFont>,
) {
commands
.spawn(Self)
.insert(Text::new(TITLE))
.insert(TextFont {
font: (**font).clone(),
font_size: 120.0,
..default()
})
.insert(TextLayout::new_with_justify(JustifyText::Center))
.insert(TextColor(TITLE_COLOR))
.insert(Node {
position_type: PositionType::Relative,
justify_self: JustifySelf::Center,
..default()
})
;
}
...
} Then I added the first system in the impl Plugin for NanpurePlugin {
fn build(&self, app: &mut App) {
app
.add_systems(Main, Self::setup)
.init_state::<GameState>()
// Main menu
.add_systems(OnEnter(GameState::MainMenu), MainMenu::spawn)
.add_systems(OnExit(GameState::MainMenu), MainMenu::despawn)
;
}
} But I’m getting the following error:
Shouldn’t What am I doing wrong? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
You probably want to add |
Beta Was this translation helpful? Give feedback.
I am guessing that the
MainMenu
state is the initial state? That case I can reproduce. It seems that the first run of theOnEnter
schedule happens before Startup/Main. That kind of makes sense to have the correct state already available during the first run of theMain
schedule.I would consider moving the setup into some "Setup" state before
MainMenu
.This works for me (instead of in
Startup
, you could also run the setup inOnEnter
ofSetup
state now):