Skip to content

Commit 2a28665

Browse files
author
Rene Damm
authored
FIX: PressInteraction missing presses when reset from callback (case 1205285, #1064).
1 parent c7c60c5 commit 2a28665

File tree

3 files changed

+47
-5
lines changed

3 files changed

+47
-5
lines changed

Assets/Tests/InputSystem/CoreTests_Actions_Interactions.cs

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
using System.Linq;
22
using NUnit.Framework;
3+
using UnityEngine;
34
using UnityEngine.InputSystem;
45
using UnityEngine.InputSystem.Interactions;
56
using UnityEngine.InputSystem.LowLevel;
67
using UnityEngine.InputSystem.Utilities;
7-
using UnityEngine.InputSystem.XR;
88
using UnityEngine.Scripting;
99

1010
internal partial class CoreTests
@@ -190,6 +190,47 @@ public void Actions_CanPerformPressInteraction()
190190
}
191191
}
192192

193+
// https://fogbugz.unity3d.com/f/cases/1205285/
194+
[Test]
195+
[Category("Actions")]
196+
public void Actions_CanPerformPressInteraction_AndTriggerInteractionResetInCallback()
197+
{
198+
var keyboard = InputSystem.AddDevice<Keyboard>();
199+
200+
var asset = ScriptableObject.CreateInstance<InputActionAsset>();
201+
var map1 = new InputActionMap("map1");
202+
var map2 = new InputActionMap("map2");
203+
asset.AddActionMap(map1);
204+
asset.AddActionMap(map2);
205+
206+
var action1 = map1.AddAction("action1");
207+
var action2 = map2.AddAction("action2");
208+
// PressInteraction used to set some local state *after* trigger callbacks. This meant that if the
209+
// callback triggered a Reset() call, PressInteraction would then overwrite state from the reset.
210+
action1.AddBinding("<Keyboard>/a", interactions: "press(behavior=0)");
211+
action2.AddBinding("<Keyboard>/b", interactions: "press(behavior=0)");
212+
213+
action1.performed += _ => { map1.Disable(); map2.Enable(); };
214+
action2.performed += _ => { map2.Disable(); map1.Enable(); };
215+
216+
map1.Enable();
217+
218+
PressAndRelease(keyboard.aKey);
219+
220+
Assert.That(map1.enabled, Is.False);
221+
Assert.That(map2.enabled, Is.True);
222+
223+
PressAndRelease(keyboard.bKey);
224+
225+
Assert.That(map1.enabled, Is.True);
226+
Assert.That(map2.enabled, Is.False);
227+
228+
PressAndRelease(keyboard.aKey);
229+
230+
Assert.That(map1.enabled, Is.False);
231+
Assert.That(map2.enabled, Is.True);
232+
}
233+
193234
[Test]
194235
[Category("Actions")]
195236
public void Actions_CanPerformHoldInteraction()

Packages/com.unity.inputsystem/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ however, it has to be formatted properly to pass verification tests.
1616
- Mixing the enabling&disabling of single actions (as, for example, performed by `InputSystemUIInputModule`) with enabling&disabling of entire action maps (as, for example, performed by `PlayerInput`) no longer leaves to unresponsive input and `"should not reach here"` assertions ([forum thread](https://forum.unity.com/threads/error-while-switching-between-action-maps.825204/)).
1717
- Leaving play mode no longer leaves state change monitors lingering around from enabled actions.
1818
- 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)).
19+
- `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)).
1920

2021
## [1.0.0-preview.5] - 2020-02-14
2122

Packages/com.unity.inputsystem/InputSystem/Actions/Interactions/PressInteraction.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ public void Process(ref InputInteractionContext context)
7474
}
7575
else if (isActuated)
7676
{
77-
context.PerformedAndStayPerformed();
7877
m_WaitingForRelease = true;
78+
context.PerformedAndStayPerformed();
7979
}
8080
break;
8181

@@ -88,25 +88,25 @@ public void Process(ref InputInteractionContext context)
8888
}
8989
else if (isActuated)
9090
{
91-
context.Started();
9291
m_WaitingForRelease = true;
92+
context.Started();
9393
}
9494
break;
9595

9696
case PressBehavior.PressAndRelease:
9797
if (m_WaitingForRelease)
9898
{
99+
m_WaitingForRelease = isActuated;
99100
if (!isActuated)
100101
{
101102
context.Performed();
102103
context.Canceled();
103104
}
104-
m_WaitingForRelease = isActuated;
105105
}
106106
else if (isActuated)
107107
{
108-
context.PerformedAndStayPerformed();
109108
m_WaitingForRelease = true;
109+
context.PerformedAndStayPerformed();
110110
}
111111
break;
112112
}

0 commit comments

Comments
 (0)