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
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
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
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:
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).
#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.