Path: blob/main/examples/diagnostics/custom_diagnostic.rs
6592 views
//! This example illustrates how to create a custom diagnostic.12use bevy::{3diagnostic::{4Diagnostic, DiagnosticPath, Diagnostics, LogDiagnosticsPlugin, RegisterDiagnostic,5},6prelude::*,7};89fn main() {10App::new()11.add_plugins((12DefaultPlugins,13// The "print diagnostics" plugin is optional.14// It just visualizes our diagnostics in the console.15LogDiagnosticsPlugin::default(),16))17// Diagnostics must be initialized before measurements can be added.18.register_diagnostic(Diagnostic::new(SYSTEM_ITERATION_COUNT).with_suffix(" iterations"))19.add_systems(Update, my_system)20.run();21}2223// All diagnostics should have a unique DiagnosticPath.24const SYSTEM_ITERATION_COUNT: DiagnosticPath = DiagnosticPath::const_new("system_iteration_count");2526fn my_system(mut diagnostics: Diagnostics) {27// Add a measurement of 10.0 for our diagnostic each time this system runs.28diagnostics.add_measurement(&SYSTEM_ITERATION_COUNT, || 10.0);29}303132