Skip to content

Commit 6e43bff

Browse files
authored
FIX: Exception thrown when acessing Action's bindings after changing Composite (ISXB-494) (#1966)
A simple, low-risk fix to address the immediate problem. Also adds a new test to cover this specific scenario.
1 parent 5e1b12d commit 6e43bff

3 files changed

Lines changed: 32 additions & 1 deletion

File tree

Assets/Tests/InputSystem/CoreTests_Actions.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5250,6 +5250,36 @@ public void Actions_CanAddBindingsToActions_ToExistingComposite()
52505250
composite.InsertPartBinding("Negative", "<Keyboard>/leftArrow");
52515251
composite.InsertPartBinding("Positive", "<Keyboard>/rightArrow");
52525252

5253+
ValidateCompositeBindingsOnAction(action);
5254+
}
5255+
5256+
[Test]
5257+
[Category("Actions")]
5258+
[Description("ISXB-494 Changing composite of action inside a map triggered exception that wasn't caught by previous test.")]
5259+
public void Actions_CanChangeBindingPart_ToExistingCompositeInActionMap()
5260+
{
5261+
var keyboard = InputSystem.AddDevice<Keyboard>();
5262+
5263+
var actionMap = new InputActionMap("Map");
5264+
var action = actionMap.AddAction("Action", InputActionType.Value, expectedControlLayout: "Axis");
5265+
5266+
action.AddCompositeBinding("Axis")
5267+
.With("Negative", "<Keyboard>/a")
5268+
.With("Positive", "<Keyboard>/d");
5269+
5270+
Assert.That(action.bindings, Has.Count.EqualTo(3));
5271+
Assert.That(action.controls, Is.EquivalentTo(new[] { keyboard.aKey, keyboard.dKey }));
5272+
5273+
var composite = action.ChangeCompositeBinding("Axis");
5274+
5275+
composite.InsertPartBinding("Negative", "<Keyboard>/leftArrow");
5276+
composite.InsertPartBinding("Positive", "<Keyboard>/rightArrow");
5277+
5278+
ValidateCompositeBindingsOnAction(action);
5279+
}
5280+
5281+
private void ValidateCompositeBindingsOnAction(InputAction action)
5282+
{
52535283
Assert.That(action.bindings, Has.Count.EqualTo(5));
52545284
Assert.That(action.bindings,
52555285
Has.Exactly(1).With.Property("isComposite").EqualTo(true).And.With.Property("isPartOfComposite").EqualTo(false).And.With

Packages/com.unity.inputsystem/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Due to package verification, the latest version below is the unpublished version
99
however, it has to be formatted properly to pass verification tests.
1010

1111
## [Unreleased] - yyyy-mm-dd
12+
- Fixed ArgumentNullException thrown when accessing Action's bindings after changing Composite part. [ISXB-494](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-494).
1213

1314
### Fixed
1415
- Fixed default scroll speed in uGUI being slower than before. [ISXB-766](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-766)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1609,7 +1609,7 @@ public BindingSyntax InsertPartBinding(string partName, string path)
16091609
throw new InvalidOperationException("Binding accessor must point to composite or part binding");
16101610

16111611
AddBindingInternal(m_ActionMap,
1612-
new InputBinding { path = path, isPartOfComposite = true, name = partName },
1612+
new InputBinding { path = path, isPartOfComposite = true, name = partName, action = m_Action?.name },
16131613
m_BindingIndexInMap + 1);
16141614

16151615
return new BindingSyntax(m_ActionMap, m_BindingIndexInMap + 1, m_Action);

0 commit comments

Comments
 (0)