From 4275669b07492ea66d5cf09fbd0c94c8833dafac Mon Sep 17 00:00:00 2001 From: Brandon Reinhart Date: Sun, 7 Jul 2024 20:00:04 -0500 Subject: [PATCH] impl Reflect + Clone for StateScoped (#14156) # Objective - Expand the flexibilty of StateScoped by adding Reflect and Clone - This lets StateScoped be used in Clone Bundles, for example ```rust #[derive(Component, Reflect, Clone)] pub struct StateScoped(pub S); ``` Notes: - States are already Clone. - Type registration is up to the user, but this is commonly the case with reflected generic types. ## Testing - Ran the examples. --- crates/bevy_state/src/state_scoped.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/crates/bevy_state/src/state_scoped.rs b/crates/bevy_state/src/state_scoped.rs index 9abd22e78e..5f1b2d0be3 100644 --- a/crates/bevy_state/src/state_scoped.rs +++ b/crates/bevy_state/src/state_scoped.rs @@ -1,3 +1,5 @@ +#[cfg(feature = "bevy_reflect")] +use bevy_ecs::reflect::ReflectComponent; use bevy_ecs::{ component::Component, entity::Entity, @@ -6,6 +8,8 @@ use bevy_ecs::{ }; #[cfg(feature = "bevy_hierarchy")] use bevy_hierarchy::DespawnRecursiveExt; +#[cfg(feature = "bevy_reflect")] +use bevy_reflect::prelude::*; use crate::state::{StateTransitionEvent, States}; @@ -52,7 +56,8 @@ use crate::state::{StateTransitionEvent, States}; /// app.enable_state_scoped_entities::(); /// app.add_systems(OnEnter(GameState::InGame), spawn_player); /// ``` -#[derive(Component)] +#[derive(Component, Clone)] +#[cfg_attr(feature = "bevy_reflect", derive(Reflect), reflect(Component))] pub struct StateScoped(pub S); /// Removes entities marked with [`StateScoped`]