pub fn init_resource<R>(&mut self) -> &mut Self
    where
        R: FromWorld + Send + Sync + 'static,
    {
        // PERF: We could avoid double hashing here, since the `from_resources` call is guaranteed
        // not to modify the map. However, we would need to be borrowing resources both
        // mutably and immutably, so we would need to be extremely certain this is correct
        if !self.world_mut().contains_resource::<R>() {
            let resource = R::from_world(self.world_mut());
            self.insert_resource(resource);
        }
        self
    }
/// Initialize a resource in the current [App], if it does not exist yet
///
/// Adds a resource that implements `Default` or [`FromResources`] trait.
/// If the resource already exists, `init_resource` does nothing.
///
/// ## Example
/// ```
/// # use bevy_app::prelude::*;
/// #
/// struct MyCounter {
///     counter: usize,
/// }
///
/// impl Default for MyCounter {
///     fn default() -> MyCounter {
///         MyCounter {
///             counter: 100
///         }
///     }
/// }
///
/// App::build()
///     .init_resource::<MyCounter>();
/// ```
Initialize a resource in the current [App], if it does not exist yet
Adds a resource that implements `Default` or [`FromResources`] trait.
If the resource already exists, `init_resource` does nothing.
Initialize a resource in the current [ App ] if it does not exist yet Adds a resource that implements ` Default ` or [ ` FromResources ` ] trait . If the resource already exists ` init_resource ` does nothing .
pub fn init_resource<R>(&mut self) -> &mut Self
    where
        R: FromWorld + Send + Sync + 'static,
    {
        // PERF: We could avoid double hashing here, since the `from_resources` call is guaranteed
        // not to modify the map. However, we would need to be borrowing resources both
        // mutably and immutably, so we would need to be extremely certain this is correct
        if !self.world_mut().contains_resource::<R>() {
            let resource = R::from_world(self.world_mut());
            self.insert_resource(resource);
        }
        self
    }
pub fn init_resource < R > ( & mut self ) -> & mut Self where R : FromWorld + Send + Sync + ' static , { // PERF: We could avoid double hashing here, since the `from_resources` call is guaranteed // not to modify the map. However, we would need to be borrowing resources both // mutably and immutably, so we would need to be extremely certain this is correct if ! self . world_mut ( ) . contains_resource :: < R > ( ) { let resource = R :: from_world ( self . world_mut ( ) ) ; self . insert_resource ( resource ) ; } self }
Initialize a resource in the current [App], if it does not exist yet
Adds a resource that implements `Default` or [`FromResources`] trait.
Initialize a resource in the current [ App ] if it does not exist yet Adds a resource that implements ` Default ` or [ ` FromResources ` ] trait .
&mut self
&mut self
example
None
use bevy_app::prelude::*;
struct MyCounter {
counter: usize,
}

impl Default for MyCounter {
fn default() -> MyCounter {
MyCounter {
counter: 100
}
}
}


struct MyCounter { counter : usize } impl Default for MyCounter { fn default () - > MyCounter { MyCounter { counter : 100 } } }