From d3731fd2d459e2b774117d6ca74deb0c765f092d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ha=CC=8Akan=20Sidenvall?= Date: Wed, 15 Apr 2026 16:30:42 +0200 Subject: [PATCH] FIX: Relaxing timestamp arithmetic error tolerance due to some platforms (Android) reporting timestamps out of order with respect to sequence in sub-decimal range. --- .../InputSystem/InputManager.cs | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/Packages/com.unity.inputsystem/InputSystem/InputManager.cs b/Packages/com.unity.inputsystem/InputSystem/InputManager.cs index 128aca347c..2abac9ad80 100644 --- a/Packages/com.unity.inputsystem/InputSystem/InputManager.cs +++ b/Packages/com.unity.inputsystem/InputSystem/InputManager.cs @@ -3731,19 +3731,22 @@ private unsafe void ProcessStateEvent(InputDevice device, InputUpdateType update // that are generated in the backend and would require considerable work to ensure monotonically // increasing timestamps across all such streams. var deviceIsStateCallbackReceiver = device.hasStateCallbacks; +#if UNITY_ANDROID + // Android keyboards can send events out of order: Holding down a key will send multiple + // presses after a short time, like on most platforms. Unfortunately, on Android, the + // last of these "presses" can be timestamped to be after the event of the key release. + // If that happens, we'd skip the keyUp here, and the device state will have the key + // "stuck" pressed. So, special case here to not skip keyboard events on Android. ISXB-475 + // N.B. Android seems to have similar issues with touch input (OnStateEvent, Touchscreen.cs) + // Android also seems to have similar issue with mouse input, see UUM-136430. + if (currentEventTimeInternal < device.m_LastUpdateTimeInternal - 1e-3 && /* 1 ms accepted error */ +#else if (currentEventTimeInternal < device.m_LastUpdateTimeInternal && +#endif !(deviceIsStateCallbackReceiver && device.stateBlock.format != eventPtr.stateFormat)) { #if UNITY_EDITOR m_Diagnostics?.OnEventTimestampOutdated(new InputEventPtr(currentEventReadPtr), device); -#elif UNITY_ANDROID - // Android keyboards can send events out of order: Holding down a key will send multiple - // presses after a short time, like on most platforms. Unfortunately, on Android, the - // last of these "presses" can be timestamped to be after the event of the key release. - // If that happens, we'd skip the keyUp here, and the device state will have the key - // "stuck" pressed. So, special case here to not skip keyboard events on Android. ISXB-475 - // N.B. Android seems to have similar issues with touch input (OnStateEvent, Touchscreen.cs) - if (!(device is Keyboard)) #endif return; }