From 23dbcf921568fcb0fe200c0fae672f5091c90d18 Mon Sep 17 00:00:00 2001 From: Jean Mertz Date: Fri, 17 Jan 2025 02:19:09 +0100 Subject: [PATCH] impl Default for StateScoped (#17401) This allows this: ```rust #[derive(Component)] #[require(StateScoped(StateScoped(MyState)))] struct ComponentA; ``` To be shortened to this: ```rust #[derive(Component)] #[require(StateScoped)] struct ComponentA; ``` When `MyState` implements `Default`. Signed-off-by: Jean Mertz --- crates/bevy_state/src/state_scoped.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/crates/bevy_state/src/state_scoped.rs b/crates/bevy_state/src/state_scoped.rs index 3e9f49f517..02a8c75cdc 100644 --- a/crates/bevy_state/src/state_scoped.rs +++ b/crates/bevy_state/src/state_scoped.rs @@ -60,6 +60,15 @@ use crate::state::{StateTransitionEvent, States}; #[cfg_attr(feature = "bevy_reflect", derive(Reflect), reflect(Component))] pub struct StateScoped(pub S); +impl Default for StateScoped +where + S: States + Default, +{ + fn default() -> Self { + Self(S::default()) + } +} + /// Removes entities marked with [`StateScoped`] /// when their state no longer matches the world state. ///