Skip to content

Commit e270c16

Browse files
authored
Fixed an issue where resetting an action via InputAction.Reset() while being in disabled state would prevent the action from being enabled again. (#1419)
1 parent 9b58cee commit e270c16

File tree

3 files changed

+41
-1
lines changed

3 files changed

+41
-1
lines changed

Assets/Tests/InputSystem/CoreTests_Actions.cs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8792,6 +8792,41 @@ public void Actions_CanResetAction()
87928792
}
87938793
}
87948794

8795+
// Corresponds to bug report ticket 1370732.
8796+
[Test]
8797+
[Category("Actions")]
8798+
public void Actions_ResetShouldPreserveEnabledState__IfResetWhileInDisabledState()
8799+
{
8800+
var gamepad = InputSystem.AddDevice<Gamepad>();
8801+
8802+
InputSystem.settings.defaultDeadzoneMin = 0;
8803+
InputSystem.settings.defaultDeadzoneMax = 1;
8804+
8805+
var action = new InputAction(type: InputActionType.Value, binding: "<Gamepad>/leftStick");
8806+
action.Enable();
8807+
Assert.That(action.enabled, Is.True);
8808+
8809+
action.Disable();
8810+
Assert.That(action.enabled, Is.False);
8811+
8812+
action.Reset();
8813+
Assert.That(action.enabled, Is.False);
8814+
8815+
action.Enable();
8816+
Assert.That(action.enabled, Is.True);
8817+
8818+
using (var trace = new InputActionTrace(action))
8819+
{
8820+
Set(gamepad.leftStick, new Vector2(0.2f, 0.3f));
8821+
8822+
Assert.That(action.inProgress, Is.True);
8823+
Assert.That(action.ReadValue<Vector2>(), Is.EqualTo(new Vector2(0.2f, 0.3f)));
8824+
Assert.That(trace,
8825+
Started(action, value: new Vector2(0.2f, 0.3f))
8826+
.AndThen(Performed(action, value: new Vector2(0.2f, 0.3f))));
8827+
}
8828+
}
8829+
87958830
private class MonoBehaviourWithActionProperty : MonoBehaviour
87968831
{
87978832
public InputActionProperty actionProperty;

Packages/com.unity.inputsystem/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ however, it has to be formatted properly to pass verification tests.
2424
- Fixed a problem where only using runtimes that are not XR supported causes a compile error.This fix adds back in ENABLE_VR checks to prevent this case (case 1368300)
2525
- Fixed input action for Android gamepad's right stick will be correctly invoked when only y axis is changing ([case 1308637](https://issuetracker.unity3d.com/issues/android-input-system-right-analog-stick-tracking-is-erratic-when-using-a-gamepad-connected-to-an-android-device)).
2626
- Generic gamepad short display button names where incorrectly mapped on Switch (`A` instead of `B`, etc).
27+
- Fixed an issue where resetting an action via `InputAction.Reset()` while being in disabled state would prevent the action from being enabled again. ([case 1370732](https://issuetracker.unity3d.com/product/unity/issues/guid/1370732/)).
2728
- Fixed "Default constructor not found for type UnityEngine.InputSystem.iOS.LowLevel.iOSStepCounter" any other potential exceptions due to classes, methods, fields and properties being stripped when managed stripping setting set to medium or high ([case 1368761](https://issuetracker.unity3d.com/issues/ios-new-input-system-iosstepcounter-crash-on-launch-with-managed-stripping)).
2829

2930
### Added

Packages/com.unity.inputsystem/InputSystem/Actions/InputAction.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1032,13 +1032,17 @@ public unsafe object ReadValueAsObject()
10321032
/// <remarks>
10331033
/// This method can be used to forcibly cancel an action even while it is in progress. Note that unlike
10341034
/// disabling an action, for example, this also effects APIs such as <see cref="WasPressedThisFrame"/>.
1035+
///
1036+
/// Note that invoking this method will not modify enabled state.
10351037
/// </remarks>
10361038
/// <seealso cref="inProgress"/>
10371039
/// <seealso cref="phase"/>
1040+
/// <seealso cref="Enable"/>
1041+
/// <seealso cref="Disable"/>
10381042
public void Reset()
10391043
{
10401044
var state = GetOrCreateActionMap().m_State;
1041-
state?.ResetActionState(m_ActionIndexInState, hardReset: true);
1045+
state?.ResetActionState(m_ActionIndexInState, toPhase: enabled ? InputActionPhase.Waiting : InputActionPhase.Disabled, hardReset: true);
10421046
}
10431047

10441048
/// <summary>

0 commit comments

Comments
 (0)