mirror of
https://github.com/bevyengine/bevy
synced 2024-11-10 07:04:33 +00:00
Initialize DiagnosticStore
on register_diagnostic
if it does not exist (#8819)
# Objective - Fixes #8782 ## Solution - Call `init_resource` on `register_diagnostic` so that a `DiagnosticStore` gets initialized if it does not exist. --------- Co-authored-by: François <mockersf@gmail.com>
This commit is contained in:
parent
1977b6daf2
commit
2b4fc10ccf
1 changed files with 4 additions and 2 deletions
|
@ -289,6 +289,8 @@ pub trait RegisterDiagnostic {
|
|||
impl RegisterDiagnostic for App {
|
||||
/// Register a new [`Diagnostic`] with an [`App`].
|
||||
///
|
||||
/// Will initialize a [`DiagnosticsStore`] if it doesn't exist.
|
||||
///
|
||||
/// ```rust
|
||||
/// use bevy_app::App;
|
||||
/// use bevy_diagnostic::{Diagnostic, DiagnosticsPlugin, DiagnosticId, RegisterDiagnostic};
|
||||
|
@ -296,12 +298,12 @@ impl RegisterDiagnostic for App {
|
|||
/// const UNIQUE_DIAG_ID: DiagnosticId = DiagnosticId::from_u128(42);
|
||||
///
|
||||
/// App::new()
|
||||
/// .add_plugin(DiagnosticsPlugin)
|
||||
/// // Must only be called after the `DiagnosticsPlugin` has been added.
|
||||
/// .register_diagnostic(Diagnostic::new(UNIQUE_DIAG_ID, "example", 10))
|
||||
/// .add_plugin(DiagnosticsPlugin)
|
||||
/// .run();
|
||||
/// ```
|
||||
fn register_diagnostic(&mut self, diagnostic: Diagnostic) -> &mut Self {
|
||||
self.init_resource::<DiagnosticsStore>();
|
||||
let mut diagnostics = self.world.resource_mut::<DiagnosticsStore>();
|
||||
diagnostics.add(diagnostic);
|
||||
|
||||
|
|
Loading…
Reference in a new issue