Skip to content

Commit 3a454e8

Browse files
authored
FIX: Fixed disabling composite binding while pressed (ISXB-505) (#1926)
* Fixed disabling composite binding while pressed
1 parent c2f4dea commit 3a454e8

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed

Assets/Tests/InputSystem/CoreTests_Actions.cs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1443,6 +1443,46 @@ public void Actions_CanDisableAndEnableOtherAction_FromCallback()
14431443
Assert.That(receivedCalls, Is.EqualTo(2));
14441444
}
14451445

1446+
[Test]
1447+
[Category("Actions")]
1448+
public void Actions_CanDisableAndEnable_FromCallbackWhileOtherCompositeBindingIsProgress()
1449+
{
1450+
// Enables "Modifier must be pressed first" behavior on all Composite Bindings
1451+
InputSystem.settings.shortcutKeysConsumeInput = true;
1452+
1453+
var keyboard = InputSystem.AddDevice<Keyboard>();
1454+
var map = new InputActionMap("map");
1455+
1456+
var withModiferReceivedCalls = 0;
1457+
var actionWithModifier = map.AddAction("OneModifier", type: InputActionType.Button);
1458+
actionWithModifier.AddCompositeBinding("OneModifier")
1459+
.With("Binding", "<Keyboard>/space")
1460+
.With("Modifier", "<Keyboard>/ctrl");
1461+
actionWithModifier.performed += _ => ++ withModiferReceivedCalls;
1462+
1463+
var actionWithoutModifier = map.AddAction("One", type: InputActionType.Button, binding: "<Keyboard>/space");
1464+
actionWithoutModifier.performed += _ => actionWithModifier.Disable();
1465+
1466+
map.Enable();
1467+
1468+
// Press the SPACE key used by both binding
1469+
// actionWithModifier : SPACE key binding state will have current time but without a preceding CTRL key it will not trigger
1470+
// actionWithoutModifier : SPACE key binding will trigger the performed lambda which will disable actionWithModifier
1471+
PressAndRelease(keyboard.spaceKey);
1472+
InputSystem.Update();
1473+
Assume.That(actionWithModifier.enabled, Is.False);
1474+
1475+
// Re-enable action which has been disabled by actionWithoutModifier
1476+
actionWithModifier.Enable();
1477+
1478+
// Press the CTRL+SPACE to trigger actionWithModifier and not actionWithoutModifier
1479+
Press(keyboard.leftCtrlKey, queueEventOnly: true);
1480+
Press(keyboard.spaceKey);
1481+
InputSystem.Update();
1482+
Assert.That(withModiferReceivedCalls, Is.EqualTo(1));
1483+
Assert.That(actionWithModifier.enabled, Is.True);
1484+
}
1485+
14461486
[Test]
14471487
[Category("Actions")]
14481488
public void Actions_WhenEnabled_TriggerNotification()

Packages/com.unity.inputsystem/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ however, it has to be formatted properly to pass verification tests.
1111
## [Unreleased] - yyyy-mm-dd
1212
- Fixed Composite binding isn't triggered after ResetDevice() called during Action handler [ISXB-746](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-746)
1313
- Fixed resource designation for "d_InputControl" icon to address CI failure
14+
- Fixed Composite binding isn't triggered after disabling action while there are in progress [ISXB-505](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-505)
1415

1516
## [1.8.2] - 2024-04-29
1617

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1164,6 +1164,9 @@ private void DisableControls(int mapIndex, int controlStartIndex, int numControl
11641164
SetInitialStateCheckPending(bindingStatePtr, false);
11651165
manager.RemoveStateChangeMonitor(controls[controlIndex], this, mapControlAndBindingIndex);
11661166

1167+
// Ensure that pressTime is reset if the composite binding is reenable. ISXB-505
1168+
bindingStatePtr->pressTime = default;
1169+
11671170
SetControlEnabled(controlIndex, false);
11681171
}
11691172
}

0 commit comments

Comments
 (0)