Skip to content

Commit 2bdf412

Browse files
fixed event discarding for forward peeking and instead soft reset the device
1 parent 8c159e8 commit 2bdf412

1 file changed

Lines changed: 15 additions & 8 deletions

File tree

Packages/com.unity.inputsystem/InputSystem/InputManager.cs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3492,19 +3492,26 @@ private unsafe void ProcessBeforeRenderStateEvents(out InputDevice device, out I
34923492
private unsafe bool SkipEventDueToEditorBehaviour(InputUpdateType updateType, FourCC currentEventType, bool dropStatusEvents, double currentEventTimeInternal)
34933493
{
34943494
var focusEventType = new FourCC(FocusConstants.kEventType);
3495-
var possibleFocusEvent = m_InputEventStream.Peek();
34963495

3497-
if (possibleFocusEvent != null)
3496+
// Check if the next event is a FocusEvent. If so, cancel any in-progress actions before
3497+
// the focus change to prevent half-processed action states (e.g., Started without Performed).
3498+
// This avoids the problem of dropping individual events (which can cause button stuck states)
3499+
// by instead explicitly resetting action state at the right time.
3500+
var possibleFocusEvent = m_InputEventStream.Peek();
3501+
if (possibleFocusEvent != null && possibleFocusEvent->type == focusEventType &&
3502+
!gameShouldGetInputRegardlessOfFocus)
34983503
{
3499-
if (possibleFocusEvent->type == focusEventType && !gameShouldGetInputRegardlessOfFocus)
3504+
// Cancel all in-progress actions for all devices to prevent actions getting stuck
3505+
// in Started phase when focus changes cause events to be routed differently.
3506+
// We use SoftReset which cancels actions but doesn't reset device state.
3507+
for (var i = 0; i < m_DevicesCount; ++i)
35003508
{
3501-
// If the next event is a focus event and we're not supposed to get input of the current update type in the next one, drop current event.
3502-
// This ensures that we don't end up with a half processed events due to swapping buffers between editor and player,
3503-
// such as InputActionPhase.Started not being finished by a InputActionPhase.Performed and ending up in a pressed state in the previous update type
3504-
m_InputEventStream.Advance(false);
3505-
return true;
3509+
var device = m_Devices[i];
3510+
if (device.enabled)
3511+
InputActionState.OnDeviceChange(device, InputDeviceChange.SoftReset);
35063512
}
35073513
}
3514+
35083515
// When the game is playing and has focus, we never process input in editor updates.
35093516
// All we do is just switch to editor state buffers and then exit.
35103517
if (gameIsPlaying && gameHasFocus && updateType == InputUpdateType.Editor

0 commit comments

Comments
 (0)