Skip to content

Commit 47cfc02

Browse files
committed
Fix for onAnyButtonPress not recognizing touch anymore
1 parent 2d1a606 commit 47cfc02

3 files changed

Lines changed: 30 additions & 1 deletion

File tree

Assets/Tests/InputSystem/CoreTests_Events.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,34 @@ public void Events_OnAnyButtonPressed_FiltersOutOtherControls()
218218

219219
Assert.That(callCount, Is.EqualTo(1));
220220
}
221+
222+
[Test]
223+
[Category("Events")]
224+
public void Events_OnAnyButtonPressed_WorksWithTouchControls()
225+
{
226+
InputSystem.settings.defaultButtonPressPoint = 0.5f;
227+
228+
var touch = InputSystem.AddDevice<Touchscreen>();
229+
230+
var callCount = 0;
231+
232+
InputSystem.onAnyButtonPress
233+
.Call(ctrl =>
234+
{
235+
Assert.That(ctrl, Is.SameAs(touch.touches[0].press));
236+
++callCount;
237+
});
238+
239+
Assert.That(callCount, Is.Zero);
240+
241+
InputSystem.Update();
242+
243+
SetTouch(0,TouchPhase.Began, new Vector2(12,12));
244+
245+
InputSystem.Update();
246+
247+
Assert.That(callCount, Is.EqualTo(1));
248+
}
221249

222250
[Test]
223251
[Category("Events")]

Packages/com.unity.inputsystem/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
2121
- Fixed `buttonSouth` returning the state of the east button (and so on for all the compass named buttons) when using a Nintendo Switch Pro Controller on iOS [ISXB-1632](issuetracker.unity3d.com/product/unity/issues/guid/ISXB-1632)
2222
- Fixed `aButton` returning the state of the east button (and so on for all the letter named buttons) when using a Nintendo Switch Pro Controller on Standalone & iOS [ISXB-1632](issuetracker.unity3d.com/product/unity/issues/guid/ISXB-1632)
2323
- Fixed an issue where `UIToolkit` `ClickEvent` could be fired on Android after device rotation due to inactive touch state being replayed during action initial state checks [UUM-100125](https://jira.unity3d.com/browse/UUM-100125).
24+
- Fixed InputSystem.onAnyButtonPress fails to trigger when the device receives a touch [UUM-137930](https://issuetracker.unity3d.com/product/unity/issues/guid/UUM-137930).
2425

2526
### Changed
2627

Packages/com.unity.inputsystem/InputSystem/Controls/InputControlExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1114,7 +1114,7 @@ public static InputControl GetFirstButtonPressOrNull(this InputEventPtr eventPtr
11141114

11151115
foreach (var control in eventPtr.EnumerateControls(Enumerate.IgnoreControlsInDefaultState, magnitudeThreshold: magnitude))
11161116
{
1117-
if (!control.HasValueChangeInEvent(eventPtr))
1117+
if (!control.HasValueChangeInEvent(eventPtr) && !(control.device is Touchscreen)) // touches can happen to not have a previous state to compare to after the touch started
11181118
continue;
11191119
if (buttonControlsOnly && !control.isButton)
11201120
continue;

0 commit comments

Comments
 (0)