Diagnostics / Enabling/disabling diagnostic

Back to examples View in GitHub

Support Warning

WebGPU is currently only supported on Chrome starting with version 113, and only on desktop. If they don't work on your configuration, you can check the WebGL2 examples here.

enabling_disabling_diagnostic.rs:
//! Shows how to disable/re-enable a Diagnostic during runtime

use std::time::Duration;

use bevy::{
    diagnostic::{DiagnosticsStore, FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin},
    prelude::*,
    time::common_conditions::on_timer,
};

fn main() {
    App::new()
        .add_plugins((
            DefaultPlugins,
            FrameTimeDiagnosticsPlugin,
            LogDiagnosticsPlugin::default(),
        ))
        .add_systems(
            Update,
            toggle.run_if(on_timer(Duration::from_secs_f32(10.0))),
        )
        .run();
}

fn toggle(mut store: ResMut<DiagnosticsStore>) {
    for diag in store.iter_mut() {
        info!("toggling diagnostic {}", diag.path());
        diag.is_enabled = !diag.is_enabled;
    }
}