Skip to content

Latest commit

 

History

History
92 lines (73 loc) · 1.97 KB

the_default_scheduler_for_systems.md

File metadata and controls

92 lines (73 loc) · 1.97 KB

The Default Scheduler For Systems

Previously, we use add_systems to execute a function.

add_systems(Startup, hello)

The Startup struct indicates the moment when function hello is executed. There are other structs that help us executing functions at different moments, as shown in the following code. These structs can be found in the description of the Main schedule.

use bevy::app::{
    App, First, Last, PostStartup, PostUpdate, PreStartup, PreUpdate, RunFixedUpdateLoop, Startup,
    StateTransition, Update,
};

fn main() {
    App::new()
        .add_systems(First, first)
        .add_systems(Last, last)
        .add_systems(PostStartup, post_startup)
        .add_systems(PostUpdate, post_update)
        .add_systems(PreStartup, pre_startup)
        .add_systems(PreUpdate, pre_update)
        .add_systems(RunFixedUpdateLoop, run_fixed_update_loop)
        .add_systems(Startup, startup)
        .add_systems(StateTransition, state_transition)
        .add_systems(Update, update)
        .run();
}

fn first() {
    println!("First");
}

fn last() {
    println!("Last");
}

fn post_startup() {
    println!("PostStartup");
}

fn post_update() {
    println!("PostUpdate");
}

fn pre_startup() {
    println!("PreStartup");
}

fn pre_update() {
    println!("PreUpdate");
}

fn run_fixed_update_loop() {
    println!("RunFixedUpdateLoop");
}

fn startup() {
    println!("Startup");
}

fn state_transition() {
    println!("StateTransition");
}

fn update() {
    println!("Update");
}

Output:

PreStartup
Startup
PostStartup
First
PreUpdate
StateTransition
RunFixedUpdateLoop
Update
PostUpdate
Last

➡️ Next: Executing Multiple Systems Simultaneously

📘 Back: Table of contents