Repository: bevyengine/bevy
File: crates/bevy_state/src/app.rs (Rust)

Code before:
        self.register_type::<State<S>>();
        self.register_type_data::<S, crate::reflect::ReflectState>();
        self
    }

    #[cfg(feature = "bevy_reflect")]
    fn register_type_mutable_state<S>(&mut self) -> &mut Self
    where
        S: FreelyMutableState + FromReflect + GetTypeRegistration + Typed,
    {
        self.register_type::<S>();
        self.register_type::<State<S>>();
        self.register_type::<NextState<S>>();
        self.register_type_data::<S, crate::reflect::ReflectState>();
        self.register_type_data::<S, crate::reflect::ReflectFreelyMutableState>();
        self
    }
}

fn enable_state_scoped_entities<S: States>(app: &mut SubApp) {
    if !app
        .world()
        .contains_resource::<Events<StateTransitionEvent<S>>>()
    {
        let name = core::any::type_name::<S>();
        warn!("State scoped entities are enabled for state `{name}`, but the state isn't installed in the app!");
    }

    // Note: We work with `StateTransition` in set
    // `StateTransitionSystems::ExitSchedules` rather than `OnExit`, because
    // `OnExit` only runs for one specific variant of the state.
    app.add_systems(
        StateTransition,
        despawn_entities_on_exit_state::<S>.in_set(StateTransitionSystems::ExitSchedules),
    )
    // Note: We work with `StateTransition` in set
    // `StateTransitionSystems::EnterSchedules` rather than `OnEnter`, because
    // `OnEnter` only runs for one specific variant of the state.
    .add_systems(
        StateTransition,
        despawn_entities_on_enter_state::<S>.in_set(StateTransitionSystems::EnterSchedules),
    );
}

impl AppExtStates for App {
    fn init_state<S: FreelyMutableState + FromWorld>(&mut self) -> &mut Self {
        self.main_mut().init_state::<S>();
        self
    }

    fn insert_state<S: FreelyMutableState>(&mut self, state: S) -> &mut Self {

Review comment (suggestion):
```suggestion
        warn!("State scoped entities are enabled for state `{name}`, but the state wasn't initialized in the app!");
```

Code after:
        self.register_type::<State<S>>();
        self.register_type_data::<S, crate::reflect::ReflectState>();
        self
    }

    #[cfg(feature = "bevy_reflect")]
    fn register_type_mutable_state<S>(&mut self) -> &mut Self
    where
        S: FreelyMutableState + FromReflect + GetTypeRegistration + Typed,
    {
        self.register_type::<S>();
        self.register_type::<State<S>>();
        self.register_type::<NextState<S>>();
        self.register_type_data::<S, crate::reflect::ReflectState>();
        self.register_type_data::<S, crate::reflect::ReflectFreelyMutableState>();
        self
    }
}

fn enable_state_scoped_entities<S: States>(app: &mut SubApp) {
    if !app
        .world()
        .contains_resource::<Events<StateTransitionEvent<S>>>()
    {
        let name = core::any::type_name::<S>();
        warn!("State scoped entities are enabled for state `{name}`, but the state wasn't initialized in the app!");
    }

    // Note: We work with `StateTransition` in set
    // `StateTransitionSystems::ExitSchedules` rather than `OnExit`, because
    // `OnExit` only runs for one specific variant of the state.
    app.add_systems(
        StateTransition,
        despawn_entities_on_exit_state::<S>.in_set(StateTransitionSystems::ExitSchedules),
    )
    // Note: We work with `StateTransition` in set
    // `StateTransitionSystems::EnterSchedules` rather than `OnEnter`, because
    // `OnEnter` only runs for one specific variant of the state.
    .add_systems(
        StateTransition,
        despawn_entities_on_enter_state::<S>.in_set(StateTransitionSystems::EnterSchedules),
    );
}

impl AppExtStates for App {
    fn init_state<S: FreelyMutableState + FromWorld>(&mut self) -> &mut Self {
        self.main_mut().init_state::<S>();
        self
    }

    fn insert_state<S: FreelyMutableState>(&mut self, state: S) -> &mut Self {