Skip to content

Commit 65357c2

Browse files
authored
FIX: interactions reset when performed is triggered by the cancelation the current active interaction (ISXB-310) (#1963)
* fixed interactions reset when performed is triggered by the cancelation the current active interaction * fix doc and format
1 parent 230cfd6 commit 65357c2

4 files changed

Lines changed: 55 additions & 3 deletions

File tree

Assets/Tests/InputSystem/CoreTests_Actions_Interactions.cs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,48 @@ public void Actions_WhenTransitioningFromOneInteractionToNext_GetCallbacks()
231231
}
232232
}
233233

234+
// https://jira.unity3d.com/browse/ISXB-310
235+
[Test]
236+
[Category("Actions")]
237+
public void Actions_WhenTransitioningFromOneInteractionToNextAlreadyPerformed_GetCallbacksAndResetOtherInteractions()
238+
{
239+
ResetTime();
240+
241+
var gamepad = InputSystem.AddDevice<Gamepad>();
242+
243+
var action = new InputAction("test", InputActionType.Button, binding: "<Gamepad>/buttonSouth",
244+
interactions: "multiTap(tapCount=3),multiTap,Tap");
245+
action.Enable();
246+
247+
using (var trace = new InputActionTrace(action))
248+
{
249+
// Trigger the second interaction with a double tap which also internally performs a tap on the third one.
250+
PressAndRelease(gamepad.buttonSouth);
251+
PressAndRelease(gamepad.buttonSouth, 0.2);
252+
currentTime = 2;
253+
InputSystem.Update();
254+
Assert.That(trace,
255+
Started<MultiTapInteraction>(action, gamepad.buttonSouth, time: 0)
256+
.AndThen(Canceled<MultiTapInteraction>(action, gamepad.buttonSouth, duration: 2))
257+
.AndThen(Started<MultiTapInteraction>(action, gamepad.buttonSouth))
258+
.AndThen(Performed<MultiTapInteraction>(action, gamepad.buttonSouth, duration: 0.2)));
259+
260+
trace.Clear();
261+
262+
// Trigger the third interaction with a tap and ensure that doesn't come from the previous one.
263+
PressAndRelease(gamepad.buttonSouth, time: 4);
264+
currentTime = 6;
265+
InputSystem.Update();
266+
Assert.That(trace,
267+
Started<MultiTapInteraction>(action, gamepad.buttonSouth, time: 4)
268+
.AndThen(Canceled<MultiTapInteraction>(action, gamepad.buttonSouth, duration: 2))
269+
.AndThen(Started<MultiTapInteraction>(action, gamepad.buttonSouth, time: 4))
270+
.AndThen(Canceled<MultiTapInteraction>(action, gamepad.buttonSouth, duration: 2))
271+
.AndThen(Started<TapInteraction>(action, gamepad.buttonSouth, time: 4))
272+
.AndThen(Performed<TapInteraction>(action, gamepad.buttonSouth, time: 4)));
273+
}
274+
}
275+
234276
[Test]
235277
[Category("Actions")]
236278
public void Actions_CanPerformPressInteraction()

Packages/com.unity.inputsystem/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ however, it has to be formatted properly to pass verification tests.
1212

1313
### Fixed
1414
- Fixed default scroll speed in uGUI being slower than before. [ISXB-766](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-766)
15+
- Fixed an issue when multiple interactions drive an action and perform during the cancelation of the current active interaction [ISXB-310](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-310).
1516

1617
### Added
1718
- Added `InputSystemUIInputModule.scrollDeltaPerTick` property, a customizable multiplicative factor applied to the scroll wheel speed before it is sent to UI components. Note that this has no effect on UI Toolkit content, only uGUI.

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,26 +47,27 @@ The following example demonstrates this kind of setup with a fire Action that th
4747
var fireAction = new InputAction("fire");
4848
fireAction.AddBinding("<Gamepad>/buttonSouth")
4949
// Tap fires, slow tap charges. Both act on release.
50-
.WithInteractions("tap;slowTap");
50+
.WithInteractions("tap,slowTap");
5151

5252
fireAction.started +=
5353
context =>
5454
{
55-
if (context.Interaction is SlowTapInteraction)
55+
if (context.interaction is SlowTapInteraction)
5656
ShowChargingUI();
5757
};
5858

5959
fireAction.performed +=
6060
context =>
6161
{
62-
if (context.Interaction is SlowTapInteraction)
62+
if (context.interaction is SlowTapInteraction)
6363
ChargedFire();
6464
else
6565
Fire();
6666
};
6767

6868
fireAction.canceled +=
6969
_ => HideChargingUI();
70+
fireAction.Enable();
7071
```
7172

7273
### Multiple Controls on an Action

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2266,6 +2266,14 @@ internal void ChangePhaseOfInteraction(InputActionPhase newPhase, ref TriggerSta
22662266
};
22672267
if (!ChangePhaseOfAction(InputActionPhase.Performed, ref triggerForInteraction, phaseAfterPerformedOrCanceled))
22682268
return;
2269+
2270+
// We performed the action,
2271+
// so reset remaining interaction to waiting state.
2272+
for (; i < numInteractions; ++i)
2273+
{
2274+
index = interactionStartIndex + i;
2275+
ResetInteractionState(index);
2276+
}
22692277
}
22702278
break;
22712279
}

0 commit comments

Comments
 (0)