Skip to content

Latest commit

 

History

History
33 lines (25 loc) · 897 Bytes

running_a_system_only_once.md

File metadata and controls

33 lines (25 loc) · 897 Bytes

Running A System Only Once

We can use run_if to restrict a system to run only once even if the system is in the Update schedule. This is done by the function run_once().

use bevy::{
    app::{App, Update},
    ecs::schedule::{common_conditions::run_once, IntoSystemConfigs},
    DefaultPlugins,
};

fn main() {
    App::new()
        .add_plugins(DefaultPlugins)
        .add_systems(Update, print.run_if(run_once()))
        .run();
}

fn print() {
    println!("A system that runs once.");
}

Output:

A system that runs once.

➡️ Next: Camera 3D

📘 Back: Table of contents