Switch Between input mods only with C++


i’m looking for a way to switch between Input modes. Like the Blueprint function “Set Input Mode UI Only”, but only in C++.

Is there a similar way in c++ to reach the same effect, or is this something you have to build entirely by yourself.

I tried looking in the UE documentation but couldn’t find anything. Maybe I got the wrong tags, not sure.

what i want:
when i open a menu in my game, the character dosn’t move anymore and i can’t look around with my mouse. but, i see now a mouse on the screen and can click on buttons in the menu like, load, save, exit game.

Open WidgetBlueprintLibrary.cpp and see what it does there when it switches the input mode.
You can do this for a lot of nodes that you want to translate to c++. In most cases the node will show you where its underlying code is under “Target” in the description:

From the cpp file of widgetBlueprintLibrary

// pick only one of the the following

// game and ui
FInputModeGameAndUI InputMode;
// game only
FInputModeGameOnly InputMode;
// ui only
FInputModeUIOnly InputMode;

PlayerController->SetInputMode(InputMode); // PlayerController = APlayerController

extra settings for widget focus and mouse

// passed in parameters of type
UWidget*  inWidgetToFocus;
EMouseLockMode InMouseLockMode;
bool bHideCursorDuringCapture;

	if (InWidgetToFocus != nullptr)

Thanks for the Replay.

i noticed that “bHideCursorDuringCapture” is not part of “FInputModeUIOnly”.

I resolve the effect by set PlayerController->bShowMouseCursor = true;

not sure this is the correct way.

1 Like