Skip to content

Latest commit

 

History

History
71 lines (54 loc) · 1.73 KB

executing_multiple_systems_in_order.md

File metadata and controls

71 lines (54 loc) · 1.73 KB

Executing Multiple Systems In Order

Systems can also be run sequentially. To do so, we use the chain method of IntoSystemConfigs. More precisely, we put multiple systems in a pair of parentheses and call the chain method of the parentheses.

use bevy::{
    app::{App, Startup},
    ecs::schedule::IntoSystemConfigs,
};

fn main() {
    App::new()
        .add_systems(Startup, (hello_a, hello_b, hello_c).chain())
        .run();
}

fn hello_a() {
    println!("Hello A!");
}

fn hello_b() {
    println!("Hello B!");
}

fn hello_c() {
    println!("Hello C!");
}

Output:

Hello A!
Hello B!
Hello C!

In addition to chain, we can also use the before or after methods. All these methods work on an individual system (a function) and a set of systems (the parentheses containing multiple functions).

add_systems(Startup, (hello_a, hello_b.after(hello_a), hello_c))

There are three possible outputs of the code above:

Hello A!
Hello B!
Hello C!
Hello A!
Hello C!
Hello B!

or

Hello C!
Hello A!
Hello B!

➡️ Next: Executing Multiple Systems Set By Set

📘 Back: Table of contents