Enhanced Input actions are cancelled by clicking a button widget

I am very new to Unreal, but I have encountered a weird problem regarding enhanced input and clicking on widgets.

My game uses third-person controls together with mouse input so that I can click on objects and their menus.

However, when I press at least two keys together, for example “W” and “A” in order to walk diagonally, and then I press a button widget, then the first key input gets cancelled.

This is kinda tough to explain, so I have made a quick demonstration GIF:

help

It is important to note that once I start walking, I am keeping the “W” and “A” keys pressed constantly, however once I press the button in the top left, the character stops walking to the right, completely ignoring this input until it is released and pressed again.

I have only added three things to the Third Person sample project:

  1. Enabled mouse cursor and mouse events in the Third-person Character Blueprint
  2. Added a simple Widget Blueprint with a Button & some text, along with a click event that prints “Hello” and then removes the button
  3. Added a simple Actor that creates the button widget when it is clicked

Below are some screenshots of the blueprints:



This is technically a duplicate of Pressing widget button with mouse click lose keyboard Enhanced input. , but it wasn’t resolved there and I feel like since I am adding a lot more information this new post is hopefully justified. However if I should post this stuff on that thread then I will do so.

I can’t help you because I too am trying to learn the deep knowledge of the Input/Widget magic. I’ve been working on my game for over a year without apply the correct methods for UI handling. It has caught up with me now, and my web of hacks is not easy to debug.
I just wanted to vent to someone and your post is the unlucky one.
Cheers.

Could try this, it worked for me.

In the project settings, uncheck “Should Flush Pressed Keys on Viewport Focus Lost”

1 Like

Yeah, having exactly the same behavior… Can’t find a solution yet, tried what the last person suggested with no changes.

Seeing as some people replied here, I did come up with a janky work around “solution”.

  1. I added a boolean variable to check whether the mouse is on the button or not, and change it accordingly using the Mouse Enter/Leave Events

  2. Then I added a new Enhanced Action for listening to Left clicks (or whatever click you want to activate the button). If the “Highlighted” variable is true, then some event that emulates “OnClicked” is called.

  3. One last thing that must be accounted for, is that if you use “On Mouse Leave” for anything else, then you need to catch whether the Mouse Button is down, since clicking on a widget always calls “On Mouse Leave” for some reason

I am sure the fancy stuff like changing colour can be done relatively easy with the Mouse Enter/Leave Events as well, but I didn’t bother.
This might cause some issues down the line like not being able to have multiple buttons in one widget, but at least this way Enhanced Input Actions are not cancelled.

You’re a godsent! I’ve been struggling on this for days.
Thanks!

I think I have tried EVERYTHING
In Unreal 5.4 I:

  • didn’t just remove the widget, I did an interface to do it
  • did reset ShowMouseCursor
  • Cleared all focus
  • THEN removed Widget and waited for next tick just to be sure
  • Set Input Mode Game Only (or Game and UI, didn’t change a thing) with Flushing Input set to true
  • Set Viewport Mouse Capture Mode back to Including Initial (it is set by default in project settings also)
  • Removed and Added back mapping contexts
  • Showed Mouse Cursor again
  • Reset Mouse Over and Click events
    But in the end, nothing helped, I’m still clueless why hovering and clicking are not working. Debug Key and enhanced input both show truthful data if LMB is pressed.
    Any more ideas?

Not sure if this will help with your particular issue, but I fixed it like this:

For me the source of this issue was input being flushed everytime the viewport widget receives focus (e.g. by clicking anywhere in the viewport). As @Stratego suggested, setting bShouldFlushPressedKeysOnViewportFocusLost = False in project settings helps, but not in all cases.

The base input mode struct FInputModeDataBase defines the following function:

virtual bool ShouldFlushInputOnViewportFocus() const { return true; };

which is not overridden in the “game only” input mode FInputModeGameOnly.
I had to extend it and override the function to return false like so:

struct FCustomInputModeGameOnly : FInputModeGameOnly
{
protected:
	virtual bool ShouldFlushInputOnViewportFocus() const override { return false; }
};

// Apply custom game only input mode without flushing input, e.g. in BeginPlay
PlayerController->SetInputMode(FCustomInputModeGameOnly());

I don’t think it’s possible to do this with pure BP, but you can then expose this custom input mode to BP in a UBlueprintFunctionLibrary. Or simply apply the input mode in your controller on BeginPlay.

1 Like