Set input mode UI only makes inputAxis Value stuck

Hi,

when I use “set input mode UI only” while my character is moving my character keeps moving on his own when going back to “input mode game” until I press W and release W again.

So for some reason the Input Axis value gets stuck on 1 even thought I am not pressing any key. Until I press and release the key then the Axis value becomes 0 again.

Is there a workaround for this? Can I reset an Input Axis somehow or anything like this? Thanks for helping :slight_smile:

For Singleplayer I use Pause / Unpause game and for Multiplayer I make a check whether the player is moving or not and if he does he can’t access the pause menu.
I don’t know if there is a specific function for resetting the Axis value manually but my workaround works fine for me

Edit: or you can set a bool to true when in UI only mode and while it’s true set the speed to 0. This was my first attempt for the Multiplayer issue but it’s no the best situation when for example an enemy player suddenly stops from high speeds for example.

Thank you for your reply! My game is single player but I can’t use pause because I want the game to keep running when the menu is open. Only letting the player pause when not moving would work I guess but that sounds quite annoying for the player since there is no real reason for having to do that. I hope I can find a workaround with less harsh side effects :confused:

Also for your second idea my player can do a lot more stuff than just moving so disabling all this manual would be a pain.

edit: I tried disabling the controller input 1 or 2 frames before opening the menu but even this did not fix the bug

I’ve experienced the exact issue today.

After digging into the C++ code of UE4, it turns out the engine will stop listening to all game-related registered input after calling SetInputModeUIOnly()


GameViewportClient.SetIgnoreInput(true);

Set the flag bIgnoreInput to true, will cause all the axis binding, action binding events be ignored, including the RELEASE event:



bool UGameViewportClient::InputAxis(FViewport* InViewport, int32 ControllerId, FKey Key, float Delta, float DeltaTime, int32 NumSamples, bool bGamepad)
{
if (IgnoreInput())
{
return false;
}

...


Since the RELEASE event is ignored, the key state (axis value) remains the same. That is probably why after changing to SetInputModeGameOnly() the character keeps moving in the same direction until you press the relevant key again (update the old axis value).

A workaround for me is to call


PlayerController->PlayerInput->FlushPressedKeys();

after SetInputModeUIOnly() to manually reset the value of all axis bindings and action bindings.

After some test runs, this method seems to fix the issue for me.

I know this is an old post, however, I hope this could help people who experienced the same problem.

Hopefully, this issue is resolved in later versions of UE.

11 Likes

Hey @rit, thanks for the tip, it worked perfectly for me !

What I did is inside a BlueprintFunctionLibrary, I have the following

BPFL.h


UFUNCTION(BlueprintCallable)
static void flushInputs(const APlayerController* PlayerController);

BPFL.cpp


#include "GameFramework/PlayerInput.h"

// ...other includes and code for other things...]

void UBPFL::flushInputs(const APlayerController* PlayerController)
{
PlayerController->PlayerInput->FlushPressedKeys();
}

This gives me a node inside blueprint that I can place before or after the Input Mode.

And that fixed my issue !
Thanks again :slight_smile:

6 Likes

You are a life saver man. Thanks for posting this!