Enhanced Input, issue with holding gamepad key, pausing game and focusing Widget

Hello,

We’ve been encountering an issue that seems related to how inputs (enhanced input) and UI focus interact with each others, we’re currently working on the version 5.4.4 of the Unreal Engine.

I’ve been able to reproduce it in a Third Person Shooter unreal template without any addition.

The issue:

In our game, whenever an input is hold on a controller (I am using a gamepad for reference), and pause is invoked (Pausing game, displaying UI, setting focus to Widget, Set Input mode, Add UI Mapping Context, Remove Gameplay Mapping context etc…), and then game is resumed, the input that is being held goes through Start, Ongoing, complete state at every frame; thus repeatedly triggering itself at every frame.

This issue is present in Builds and Editor.

I’ve attached a project (Blueprint Third Person Shooter) where I’ve reproduced this issue.

Inside this project, I’ve added a Widget (to be created, and focusing a button inside), and few nodes mapped to “End” key on pressed and release inside of the player character BP of the template.

Steps to Reproduce
The repro:

To reproduce this issue, it is pretty simple:

  • add in a blueprint a key that will pause the game
  • create a Widget, Add this widget to viewport.
  • Set Focus to a focusable element of this widget
  • On release of the key (or other means) Unpause
  • Remove the widget
  • Play with ShowDebug EnhancedInput to see the behaviour of the key you’re holding on the gamepad.
  • Hold input (Jump input for exemple, one that will show on the debugger)
  • Press debug key
  • Release Debug key
  • You should see that the input is being fired at every frame.

Hi,

Thank you for the repro project.

I did a bit of testing with this and found the following things:

-It looks like this is more of an issue where holding a key on the widget -> then removing it results in the behavior you’re seeing.

--The reason being; Holding jump on gamepad then pressing and releasing pause key only has the problematic behavior when starting PIE and after alt+tabbing out and back into editor

--Subsequent repeats (letting go of jump and releasing pause key then retrying it) results in jump returning to ongoing

--I’m seeing the issue consistently when holding pause key -> then press and hold jump -> let go of pause key

-On 5.6, as a workaround at the end of the key released, adding a flush input seems to fix this problem

-This discussion has another hacky workaround: https://forums.unrealengine.com/t/why-does-setting-input-focus-re-trigger-enhanced-input-action/1912972/3

-I tried setting up a toggle for pause instead of hold, and setting input modes with flushing, but that unfortunately didn’t seem to work with 5.4 but does in 5.6

If updating to 5.6 is not possible or if you’re looking for another workaround I can go ahead and escalate this to Epic to see any other ideas they may have.

Regards

Hello John,

First and foremost, thank you very much for your answer.

On the project we are currently working, it is not planned to update the version of the engine to 5.6. We will, unfortunately, have to deal with the issue on 5.4.

It would be very appreciated if you could bring the issue up to Epic to see if we can manage a workaround on 5.4.

I’ll check the hacky workaround in more detail as it could come in handy, however we’d like a reliable solution if possible.

Thank you again.

Best regards.

I actually found a git commit linked to this issue at: https://github.com/EpicGames/UnrealEngine/commit/21c4bc9e0e1d2b6c6d0c32a1da1cbd22fb5bad96

Would this work for you or are you looking for a non-engine change to get around this problem?

I think you would still need to add a flush through setting Input mode, or on the event released key calling flush pressed keys - here is the commit that added that to BP for enhanced input: https://github.com/EpicGames/UnrealEngine/commit/84298eea6bb8e0e0df6f1c0fd30a9ccda892d075

Hello John,

I apologise for the late answer.

I implemented the code from the commit you sent me to our version of the engine, and it seem that it is working wonders.

Thank you very much for your time and your answers.

Glad to hear! I’ll go ahead and close out this ticket, but please feel free to respond here if you have any follow-up questions.

Thank you.