diff --git a/crates/bevy_ecs/src/schedule/state.rs b/crates/bevy_ecs/src/schedule/state.rs index 3d6ae137ad0df3..1693f0adce7e36 100644 --- a/crates/bevy_ecs/src/schedule/state.rs +++ b/crates/bevy_ecs/src/schedule/state.rs @@ -262,14 +262,14 @@ where } /// Schedule a state change that replaces the active state with the given state. - /// This will fail if there is a scheduled operation, or if the given `state` matches the - /// current state + /// This will fail if there is a scheduled operation, pending transition, or if the given + /// `state` matches the current state pub fn set(&mut self, state: T) -> Result<(), StateError> { if self.stack.last().unwrap() == &state { return Err(StateError::AlreadyInState); } - if self.scheduled.is_some() { + if self.scheduled.is_some() || self.transition.is_some() { return Err(StateError::StateAlreadyQueued); } @@ -289,14 +289,14 @@ where } /// Schedule a state change that replaces the full stack with the given state. - /// This will fail if there is a scheduled operation, or if the given `state` matches the - /// current state + /// This will fail if there is a scheduled operation, pending transition, or if the given + /// `state` matches the current state pub fn replace(&mut self, state: T) -> Result<(), StateError> { if self.stack.last().unwrap() == &state { return Err(StateError::AlreadyInState); } - if self.scheduled.is_some() { + if self.scheduled.is_some() || self.transition.is_some() { return Err(StateError::StateAlreadyQueued); } @@ -321,7 +321,7 @@ where return Err(StateError::AlreadyInState); } - if self.scheduled.is_some() { + if self.scheduled.is_some() || self.transition.is_some() { return Err(StateError::StateAlreadyQueued); } @@ -342,7 +342,7 @@ where /// Same as [`Self::set`], but does a pop operation instead of a set operation pub fn pop(&mut self) -> Result<(), StateError> { - if self.scheduled.is_some() { + if self.scheduled.is_some() || self.transition.is_some() { return Err(StateError::StateAlreadyQueued); } @@ -365,9 +365,9 @@ where } /// Schedule a state change that restarts the active state. - /// This will fail if there is a scheduled operation + /// This will fail if there is a scheduled operation or a pending transition pub fn restart(&mut self) -> Result<(), StateError> { - if self.scheduled.is_some() { + if self.scheduled.is_some() || self.transition.is_some() { return Err(StateError::StateAlreadyQueued); }