Keyboard InputAction value flushed when clicking UI Button

Hello guys,

I am facing an issue that I have a hard time to deal with.

Context:
In my game I move the character with they keyboard AWSD.
When leveling up the game pauses and presents choices to the player.
Then before selecting a choice the player can hold the directions he wants to move to so its character will move right away after unpausing.

The problem:

  • This works fine when the player holds 1 key, the character moves right away in the correct direction.
  • However if the player holds down two keys (like ‘S‘ and ‘D‘) then only the last key pressed is handled by the system. Meaning the character will not move in the desired direction.

What I figured:

  • When the player click a button on the UI (to make his choice) the InputAction get reset/flush internally and then recovers. However when it recovers the system is not able to capture that two keys are being pressed and only restore the state of the last pressed key.

Logs:
LogTemp: Warning: == Movement : Left: 1 | Up: 1 | Right: 0 | Down: 0 ==
LogTemp: Warning: == Movement : Left: 1 | Up: 1 | Right: 0 | Down: 0 ==
LogTemp: Warning: == Movement : Left: 1 | Up: 1 | Right: 0 | Down: 0 ==
LogTemp: Warning: == Movement : Left: 1 | Up: 1 | Right: 0 | Down: 0 ==
LogTemp: Warning: == Movement : Left: 1 | Up: 1 | Right: 0 | Down: 0 ==
LogTemp: Warning: == Movement : Left: 1 | Up: 1 | Right: 0 | Down: 0 ==
LogTemp: Warning: == Movement : Left: 1 | Up: 1 | Right: 0 | Down: 0 ==
LogTemp: Warning: == Movement : Left: 1 | Up: 1 | Right: 0 | Down: 0 ==
LogTemp: Warning: == Movement : Left: 0 | Up: 0 | Right: 0 | Down: 0 == <<< Frame right after click the button on UI
LogTemp: Warning: == Movement : Left: 1 | Up: 0 | Right: 0 | Down: 0 ==
LogTemp: Warning: == Movement : Left: 1 | Up: 0 | Right: 0 | Down: 0 ==
LogTemp: Warning: == Movement : Left: 1 | Up: 0 | Right: 0 | Down: 0 ==
LogTemp: Warning: == Movement : Left: 1 | Up: 0 | Right: 0 | Down: 0 ==

I am suspecting the change of Focus or Mode (Game/UI) but I couldn’t find anything.
When I put a break point on the UI Button OnClicked event, the flush and recovery already happened.

Any idea?

Edit: I made a test with an empty button on HUD while playing with no pause, the same thing happened. It appears the change of focus is internally resetting the state of the keyboard inputs for one frame and then only recovers the last key pressed.

I am still looking for a way to avoid that, surely it is possible as clicking the UI should not lose the state of the keyboard keys being pressed.

Well I manage to find the correct way to fix the issue.
By making sure the Widget, Canvas and Buttons are not Focusable by unchecking the box “Is Focusable“ directly on the widget elements.

Of course you can still click the elements.