System ordering not working #3174
-
I'm trying to run two systems one after the other, with the first system inserting a resource and the second system using the resource. This is failing with error: Here's my code: struct Sprites {
idle: Handle<ColorMaterial>,
}
impl bevy::app::Plugin for Plugin {
fn build(&self, app: &mut AppBuilder) {
app
.add_startup_system(load_resources.system().label("load"))
.add_startup_system(spawn_current_enemy.system().after("load"));
}
}
fn load_resources(
mut commands: Commands,
asset_server: Res<AssetServer>,
mut materials: ResMut<Assets<ColorMaterial>>,
) {
commands.insert_resource(Sprites {
idle: materials.add(asset_server.load("x.png").into()),
});
}
fn spawn_current_enemy(
mut commands: Commands,
asset_server: Res<AssetServer>,
mut materials: ResMut<Assets<ColorMaterial>>,
sprites: Res<Sprites>,
) {
commands.spawn_bundle(SpriteBundle {
material: sprites.idle.clone(),
.. Default::default()
});
} Any ideas how to implement this correctly? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 3 replies
-
Commands are not processed until the end of the current stage, so while the systems are running in the correct order the resource won't exist in time. You need to split which stages these systems are in, by using |
Beta Was this translation helpful? Give feedback.
-
Solution: app
.add_startup_system_to_stage(StartupStage::PreStartup, load_resources.system())
.add_startup_system(spawn_current_enemy.system()); |
Beta Was this translation helpful? Give feedback.
-
Can these answers please be updated to v.0.10? |
Beta Was this translation helpful? Give feedback.
Commands are not processed until the end of the current stage, so while the systems are running in the correct order the resource won't exist in time.
You need to split which stages these systems are in, by using
add_system_to_stage
and selecting one of the variants of the StartupStage enum.