Skip to content

Commit 670f833

Browse files
FIX: InputAction.bindings.count is not updated after calling Erase() (#1637)
* Fix InputAction.bindings.count is not updated after calling Erase() * Set action when creating a BindingSyntax
1 parent 5ffb592 commit 670f833

File tree

3 files changed

+39
-3
lines changed

3 files changed

+39
-3
lines changed

Assets/Tests/InputSystem/CoreTests_Actions.cs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3607,6 +3607,40 @@ public void Actions_CanAddBindingsToActions()
36073607
Assert.That(action.controls, Has.Exactly(1).SameAs(gamepad.rightStick));
36083608
}
36093609

3610+
[Test]
3611+
[Category("Actions")]
3612+
public void Actions_CanRemoveBindingsFromActions()
3613+
{
3614+
var gamepad = InputSystem.AddDevice<Gamepad>();
3615+
var action = new InputAction();
3616+
3617+
action.AddBinding("<Gamepad>/leftStick");
3618+
action.AddBinding("<Gamepad>/rightStick");
3619+
3620+
action.AddCompositeBinding("OneModifier")
3621+
.With("Modifier", "<Keyboard>/Control")
3622+
.With("Button", "<Keyboard>/a");
3623+
3624+
// Total number of bindings should be 5: 2 normal bindings and 3 from the composite
3625+
// bindings
3626+
Assert.That(action.bindings, Has.Count.EqualTo(5));
3627+
3628+
// Since we have a composite bindings, all bindings will be removed at once
3629+
action.ChangeBinding(2).Erase();
3630+
Assert.That(action.bindings, Has.Count.EqualTo(2));
3631+
3632+
// Remove all remaining bindings
3633+
action.ChangeBinding(0).Erase();
3634+
action.ChangeBinding(0).Erase();
3635+
Assert.That(action.bindings, Has.Count.EqualTo(0));
3636+
3637+
// Add a binding to be removed
3638+
action.AddBinding("<Gamepad>/rightStick");
3639+
Assert.That(action.bindings, Has.Count.EqualTo(1));
3640+
action.ChangeBinding(0).Erase();
3641+
Assert.That(action.bindings, Has.Count.EqualTo(0));
3642+
}
3643+
36103644
[Test]
36113645
[Category("Actions")]
36123646
public void Actions_CanAddBindingsToActions_ToExistingComposite()

Packages/com.unity.inputsystem/CHANGELOG.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ however, it has to be formatted properly to pass verification tests.
1111
## [Unreleased]
1212

1313
### Fixed
14-
1514
- Fixed unclosed profiler marker in `InvokeCallbacksSafe_AnyCallbackReturnsTrue` which would lead to eventually broken profiler traces in some cases like using `PlayerInput` (case ISXB-393).
15+
- Fixed InputAction.bindings.count not getting correctly updated after removing bindings with Erase().
1616

1717
## [1.5.0] - 2023-01-24
1818

@@ -82,7 +82,6 @@ however, it has to be formatted properly to pass verification tests.
8282
- Fixed an issue where `ReadUnprocessedValueFromState` in PoseControl always returning default values.
8383
- Fix Player 1's UI controls stop working after second player joins ([case ISXB-125](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-125)))
8484

85-
8685
## [1.4.1] - 2022-05-30
8786

8887
### Fixed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -803,7 +803,7 @@ public static BindingSyntax ChangeBinding(this InputAction action, InputBinding
803803
if (bindingIndexInMap == -1)
804804
return default;
805805

806-
return new BindingSyntax(actionMap, bindingIndexInMap);
806+
return new BindingSyntax(actionMap, bindingIndexInMap, action);
807807
}
808808

809809
/// <summary>
@@ -1576,9 +1576,12 @@ public void Erase()
15761576
if (isComposite)
15771577
{
15781578
while (m_BindingIndexInMap < m_ActionMap.m_Bindings.LengthSafe() && m_ActionMap.m_Bindings[m_BindingIndexInMap].isPartOfComposite)
1579+
{
15791580
ArrayHelpers.EraseAt(ref m_ActionMap.m_Bindings, m_BindingIndexInMap);
1581+
}
15801582
}
15811583

1584+
m_Action.m_BindingsCount = m_ActionMap.m_Bindings.LengthSafe();
15821585
m_ActionMap.OnBindingModified();
15831586

15841587
// We have switched to a different binding array. For singleton actions, we need to

0 commit comments

Comments
 (0)