Skip to content

Commit fc5fd1d

Browse files
author
Rene Damm
authored
FIX: Processors on composite bindings not getting invoked (case 1207082, #1068).
1 parent 0a25029 commit fc5fd1d

File tree

5 files changed

+47
-3
lines changed

5 files changed

+47
-3
lines changed

Assets/Tests/InputSystem/CoreTests_Actions.cs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2764,6 +2764,46 @@ public void Actions_CanAddProcessorsToBindings()
27642764
Assert.That(receivedVector.Value.y, Is.EqualTo(0.5678).Within(0.00001));
27652765
}
27662766

2767+
// https://fogbugz.unity3d.com/f/cases/1207082/
2768+
[Test]
2769+
[Category("Actions")]
2770+
public void Actions_CanAddProcessorsToCompositeBindings()
2771+
{
2772+
var keyboard = InputSystem.AddDevice<Keyboard>();
2773+
2774+
var action = new InputAction();
2775+
action.AddCompositeBinding("2DVector", processors: "invertVector2(invertX=true,invertY=true)")
2776+
.With("Up", "<Keyboard>/w")
2777+
.With("Down", "<Keyboard>/s")
2778+
.With("Left", "<Keyboard>/a")
2779+
.With("Right", "<Keyboard>/d");
2780+
2781+
action.Enable();
2782+
2783+
// Left -> Right.
2784+
Press(keyboard.aKey);
2785+
2786+
Assert.That(action.ReadValue<Vector2>(), Is.EqualTo(new Vector2(1, 0)));
2787+
2788+
// Right -> Left.
2789+
Release(keyboard.aKey);
2790+
Press(keyboard.dKey);
2791+
2792+
Assert.That(action.ReadValue<Vector2>(), Is.EqualTo(new Vector2(-1, 0)));
2793+
2794+
// Up -> Down.
2795+
Release(keyboard.dKey);
2796+
Press(keyboard.wKey);
2797+
2798+
Assert.That(action.ReadValue<Vector2>(), Is.EqualTo(new Vector2(0, -1)));
2799+
2800+
// Down -> Up.
2801+
Release(keyboard.wKey);
2802+
Press(keyboard.sKey);
2803+
2804+
Assert.That(action.ReadValue<Vector2>(), Is.EqualTo(new Vector2(0, 1)));
2805+
}
2806+
27672807
[Test]
27682808
[Category("Actions")]
27692809
public void Actions_CanAddScaleProcessor()

Packages/com.unity.inputsystem/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ however, it has to be formatted properly to pass verification tests.
1818
- Leaving play mode no longer leaves state change monitors lingering around from enabled actions.
1919
- Enabling action maps with bindings that do not refer to an existing action in the map no longer leads to asserts and exceptions when input on the bindings is received ([case 1213085](https://issuetracker.unity3d.com/issues/input-system-input-actions-cause-exceptions-and-should-not-get-here-errors-to-appear-after-deleting-an-action-map)).
2020
- `PressInteraction` no longer misses the next button press if it gets reset from within the `performed` callback ([case 1205285](https://issuetracker.unity3d.com/issues/inputsystem-problem-with-button-state-after-deactivating-and-reactivating-an-action-map)).
21+
- Reading the value of a composite binding no longer causes processors from the last active part binding to be applied rather than the processors of the composite itself, if any ([case 1207082](https://issuetracker.unity3d.com/issues/input-system-invert-processors-have-no-effect-on-the-inputaction-dot-callbackcontext-value)).
2122

2223
## [1.0.0-preview.5] - 2020-02-14
2324

Packages/com.unity.inputsystem/Documentation~/ActionBindings.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Composite Bindings (that is, Bindings that are made up of other Bindings) solve
2929

3030
To see how to create Composites in the editor UI, see documentation on [editing Composite Bindings](ActionAssets.md#editing-composite-bindings).
3131

32-
To create composites in code, you can use the [`AddCompositeBinding`](../api/UnityEngine.InputSystem.InputActionSetupExtensions.html#UnityEngine_InputSystem_InputActionSetupExtensions_AddCompositeBinding_UnityEngine_InputSystem_InputAction_System_String_System_String_) syntax.
32+
To create composites in code, you can use the [`AddCompositeBinding`](../api/UnityEngine.InputSystem.InputActionSetupExtensions.html#UnityEngine_InputSystem_InputActionSetupExtensions_AddCompositeBinding_UnityEngine_InputSystem_InputAction_System_String_System_String_System_String_) syntax.
3333

3434
```CSharp
3535
myAction.AddCompositeBinding("Axis")

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ public static BindingSyntax AddBinding(this InputActionMap actionMap, InputBindi
375375
return new BindingSyntax(actionMap, null, bindingIndex);
376376
}
377377

378-
public static CompositeSyntax AddCompositeBinding(this InputAction action, string composite, string interactions = null)
378+
public static CompositeSyntax AddCompositeBinding(this InputAction action, string composite, string interactions = null, string processors = null)
379379
{
380380
if (action == null)
381381
throw new ArgumentNullException(nameof(action));
@@ -385,7 +385,7 @@ public static CompositeSyntax AddCompositeBinding(this InputAction action, strin
385385
var actionMap = action.GetOrCreateActionMap();
386386

387387
////REVIEW: use 'name' instead of 'path' field here?
388-
var binding = new InputBinding {path = composite, interactions = interactions, isComposite = true, action = action.name};
388+
var binding = new InputBinding {path = composite, interactions = interactions, processors = processors, isComposite = true, action = action.name};
389389
var bindingIndex = AddBindingInternal(actionMap, binding);
390390
return new CompositeSyntax(actionMap, action, bindingIndex);
391391
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2004,6 +2004,9 @@ internal TValue ReadValue<TValue>(int bindingIndex, int controlIndex, bool ignor
20042004
};
20052005

20062006
value = compositeOfType.ReadValue(ref context);
2007+
2008+
// Switch bindingIndex to that of composite so that we use the right processors.
2009+
bindingIndex = compositeBindingIndex;
20072010
}
20082011
else
20092012
{

0 commit comments

Comments
 (0)