Enhanced Input actions are cancelled by clicking a button widget

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.

3 Likes