Skip to content

Instantly share code, notes, and snippets.

@RJ
Created June 12, 2021 11:48
Show Gist options
  • Save RJ/3e2256f3ffa01185c0fa3c0541a34caa to your computer and use it in GitHub Desktop.
Save RJ/3e2256f3ffa01185c0fa3c0541a34caa to your computer and use it in GitHub Desktop.
Example of adding systems to stages nested in deep schedules, with bevy 0.5. Trait to add feature to AppBuilder - add_system_to_stage only works if the stage is in the root schedule.
pub trait AddSpawnSystem {
fn add_spawning_system(&mut self, system: impl Into<SystemDescriptor>) -> &mut AppBuilder;
}
impl AddSpawnSystem for AppBuilder {
fn add_spawning_system(&mut self, system: impl Into<SystemDescriptor>) -> &mut AppBuilder {
self.app.schedule.stage(stage::MAIN_SCHEDULE, |main_schedule: &mut Schedule| {
main_schedule.stage(stage::SIMULATION_SCHEDULE, |sim_schedule: &mut Schedule| {
sim_schedule.add_system_to_stage(Stages::SpawningStage, system)
})
});
self
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment