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