Skip to content

Commit 2c7f3f7

Browse files
committed
Fix to check against default for StateCallback receiver devices like TouchScreen
1 parent 6fa8100 commit 2c7f3f7

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1114,9 +1114,13 @@ public static unsafe InputControl GetFirstButtonPressOrNull(this InputEventPtr e
11141114

11151115
foreach (var control in eventPtr.EnumerateControls(Enumerate.IgnoreControlsInDefaultState, magnitudeThreshold: magnitude))
11161116
{
1117-
// Continue if the control did change in the event or did not have a previous state to compare to.
1117+
// Skip if the value didn't change. For IInputStateCallbackReceiver devices (e.g. Touchscreen),
1118+
// the event may not carry full device state, so fall back to checking the control was at
1119+
// default (not pressed) before this event.
11181120
var stateInEvent = control.GetStatePtrFromStateEvent(eventPtr);
1119-
if (stateInEvent == null || !control.CompareValue(control.currentStatePtr, stateInEvent))
1121+
var currentState = control.currentStatePtr;
1122+
if (stateInEvent != null ? !control.CompareValue(currentState, stateInEvent)
1123+
: control.CompareValue(currentState, control.defaultStatePtr))
11201124
continue;
11211125
if (buttonControlsOnly && !control.isButton)
11221126
continue;

0 commit comments

Comments
 (0)