Skip to content

Commit 954bf3c

Browse files
authored
FIX: Fixed a bug where multiple composite bindings for the same contr… (#883)
1 parent 8d4a8f1 commit 954bf3c

File tree

3 files changed

+69
-2
lines changed

3 files changed

+69
-2
lines changed

Assets/Tests/InputSystem/CoreTests_Actions.cs

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5075,6 +5075,69 @@ public void Actions_CompositesReportControlThatTriggeredTheCompositeInCallback()
50755075
LogAssert.NoUnexpectedReceived();
50765076
}
50775077

5078+
[Test]
5079+
[Category("Actions")]
5080+
// Test for case 1183314
5081+
public void Actions_CompositesInDifferentMapsTiedToSameControlsWork()
5082+
{
5083+
var keyboard = InputSystem.AddDevice<Keyboard>();
5084+
var gamepad = InputSystem.AddDevice<Gamepad>();
5085+
5086+
InputSystem.RegisterInteraction<LogInteraction>();
5087+
5088+
var map1 = new InputActionMap("map1");
5089+
var action1 = map1.AddAction("action");
5090+
action1.AddBinding("<Gamepad>/leftStick");
5091+
action1.AddCompositeBinding("Dpad")
5092+
.With("Up", "<Keyboard>/w")
5093+
.With("Down", "<Keyboard>/s")
5094+
.With("Left", "<Keyboard>/a")
5095+
.With("Right", "<Keyboard>/d");
5096+
var map2 = new InputActionMap("map2");
5097+
var action2 = map2.AddAction("action");
5098+
action2.AddBinding("<Gamepad>/leftStick");
5099+
action2.AddCompositeBinding("Dpad")
5100+
.With("Up", "<Keyboard>/w")
5101+
.With("Down", "<Keyboard>/s")
5102+
.With("Left", "<Keyboard>/a")
5103+
.With("Right", "<Keyboard>/d");
5104+
5105+
var asset = ScriptableObject.CreateInstance<InputActionAsset>();
5106+
asset.AddActionMap(map1);
5107+
asset.AddActionMap(map2);
5108+
asset.Enable();
5109+
5110+
5111+
InputControl performedControl1 = null;
5112+
InputControl performedControl2 = null;
5113+
action1.performed += ctx => performedControl1 = ctx.control;
5114+
action2.performed += ctx => performedControl2 = ctx.control;
5115+
5116+
InputSystem.QueueStateEvent(keyboard, new KeyboardState(Key.A));
5117+
InputSystem.Update();
5118+
5119+
Assert.That(performedControl1, Is.EqualTo(keyboard.aKey));
5120+
performedControl1 = null;
5121+
Assert.That(performedControl2, Is.EqualTo(keyboard.aKey));
5122+
performedControl2 = null;
5123+
5124+
InputSystem.QueueStateEvent(keyboard, new KeyboardState(Key.A, Key.W));
5125+
InputSystem.Update();
5126+
5127+
Assert.That(performedControl1, Is.EqualTo(keyboard.wKey));
5128+
performedControl1 = null;
5129+
Assert.That(performedControl2, Is.EqualTo(keyboard.wKey));
5130+
performedControl2 = null;
5131+
5132+
InputSystem.QueueStateEvent(keyboard, new KeyboardState(Key.A));
5133+
InputSystem.Update();
5134+
5135+
InputSystem.QueueStateEvent(keyboard, new KeyboardState());
5136+
InputSystem.Update();
5137+
5138+
LogAssert.NoUnexpectedReceived();
5139+
}
5140+
50785141
[Preserve]
50795142
private class CompositeWithVector2Part : InputBindingComposite<Vector2>
50805143
{

Packages/com.unity.inputsystem/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ however, it has to be formatted properly to pass verification tests.
1414
- Fixed a bug where the Input Settings Window might throw exceptions after assembly reload.
1515
- Correctly implemented `IsPointerOverGameObject` method for `InputSystemUIInputModule`.
1616

17+
### Actions
18+
19+
- Fixed a bug where multiple composite bindings for the same controls but on different action maps would throw exceptions.
20+
1721
## [1.0.0-preview] - 2019-9-20
1822

1923
### Fixed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -497,8 +497,8 @@ public unsafe void AddActionMap(InputActionMap map)
497497
}
498498
Debug.Assert(bindingStartIndexForAction < ushort.MaxValue, "Binding start index on action exceeds limit");
499499
Debug.Assert(bindingCountForAction < ushort.MaxValue, "Binding count on action exceeds limit");
500-
newMemory.actionBindingIndicesAndCounts[i * 2] = (ushort)bindingStartIndexForAction;
501-
newMemory.actionBindingIndicesAndCounts[i * 2 + 1] = (ushort)bindingCountForAction;
500+
newMemory.actionBindingIndicesAndCounts[actionIndex * 2] = (ushort)bindingStartIndexForAction;
501+
newMemory.actionBindingIndicesAndCounts[actionIndex * 2 + 1] = (ushort)bindingCountForAction;
502502

503503
// See if we may need conflict resolution on this action. Never needed for pass-through actions.
504504
// Otherwise, if we have more than one bound control or have several bindings and one of them

0 commit comments

Comments
 (0)