diff --git a/RELEASES.md b/RELEASES.md index e1f86d58..9df697b7 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -94,6 +94,9 @@ Input processors allow you to create custom logic for axis-like input manipulati - Actions can now be disabled at both the individual action and `ActionState` level - Disabling actions now resets their value, exposed via the `ActionState::reset` method - `ActionState::release_all` has been renamed to `ActionState::reset_all` and now resets the values of `Axislike` and `DualAxislike` actions +- the state of actions now continues to be updated while they are disabled. However, when checked, their value is always released / zero. + - this ensures that holding down an action, disabling it and then re-enabling it does not trigger just-pressed + - the values of disabled actions can be accessed by checking their `ActionData` directly ### Usability (0.15) diff --git a/src/action_state/mod.rs b/src/action_state/mod.rs index 7b967161..301e73b6 100644 --- a/src/action_state/mod.rs +++ b/src/action_state/mod.rs @@ -20,6 +20,8 @@ pub use action_data::*; /// /// Can be used as either a resource or as a [`Component`] on entities that you wish to control directly from player input. /// +/// # Disabling actions +/// /// Actions can be disabled in four different ways, with increasing granularity: /// /// 1. By disabling updates to all actions using a run condition on [`InputManagerSystem::Update`](crate::plugin::InputManagerSystem::Update). @@ -30,7 +32,13 @@ pub use action_data::*; /// More general mechanisms of disabling actions will cause specific mechanisms to be ignored. /// For example, if an entire action state is disabled, then enabling or disabling individual actions will have no effect. /// +/// Actions that are disabled will report as released (but not just released), and their values will be zero. +/// Under the hood, their values are still updated to avoid surprising behavior when re-enabled, +/// but they are not reported to the user using standard methods like [`ActionState::pressed`]. +/// To check the underlying values, access their [`ActionData`] directly. +/// /// # Example +/// /// ```rust /// use bevy::reflect::Reflect; /// use leafwing_input_manager::prelude::*; @@ -121,12 +129,9 @@ impl ActionState { /// The `action_data` is typically constructed from [`InputMap::process_actions`](crate::input_map::InputMap::process_actions), /// which reads from the assorted [`ButtonInput`](bevy::input::ButtonInput) resources. /// - /// If this [`ActionState`] is disabled, it will not be updated. + /// Actions that are disabled will still be updated: instead, their values will be read as released / zero. + /// You can see their underlying values by checking their [`ActionData`] directly. pub fn update(&mut self, updated_actions: UpdatedActions) { - if self.disabled { - return; - } - for (action, updated_value) in updated_actions.iter() { match updated_value { UpdatedValue::Button(pressed) => { @@ -471,6 +476,10 @@ impl ActionState { pub fn value(&self, action: &A) -> f32 { debug_assert_eq!(action.input_control_kind(), InputControlKind::Axis); + if self.action_disabled(action) { + return 0.0; + } + match self.axis_data(action) { Some(axis_data) => axis_data.value, None => 0.0, @@ -514,6 +523,10 @@ impl ActionState { pub fn axis_pair(&self, action: &A) -> Vec2 { debug_assert_eq!(action.input_control_kind(), InputControlKind::DualAxis); + if self.action_disabled(action) { + return Vec2::ZERO; + } + let action_data = self.dual_axis_data(action); action_data.map_or(Vec2::ZERO, |action_data| action_data.pair) }