Created
September 9, 2024 19:43
-
-
Save thebluefish/58bcec7ed15157dcc4130cc5cd7036f8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use bevy::prelude::*; | |
fn main() { | |
// create an alternative Update schedule with a new set of systems | |
// and store it in a resource to swap later | |
let mut update = Schedule::new(Update); | |
update.add_systems(bar); | |
let mut app = App::new(); | |
app | |
.insert_resource(AltUpdate(update)) | |
.add_systems(Update, foo) | |
// swapping a schedule cannot happen while currently in that schedule | |
// therefore this system in Update will panic | |
.add_systems(PostUpdate, flip) | |
; | |
app.update(); | |
println!("second frame"); | |
app.update(); | |
} | |
#[derive(Resource, Deref, DerefMut)] | |
struct AltUpdate(pub Schedule); | |
fn flip(mut schedules: ResMut<Schedules>, mut alt: ResMut<AltUpdate>) { | |
std::mem::swap(schedules.get_mut(Update).unwrap(), &mut *alt); | |
} | |
fn foo() { | |
println!("foo"); | |
} | |
fn bar() { | |
println!("bar"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment