Quick answer: Set input mode and cursor together: SetInputModeGameAndUI(...) + bShowMouseCursor = true. Clear UMG focus before switching back to Game mode with FSlateApplication::ClearKeyboardFocus().
Opening a pause menu in Unreal: the menu appears but the mouse is invisible. Closing the menu: the cursor stays visible during gameplay. Input mode and cursor visibility are decoupled and need to be set together.
The Three Modes
- Game:
FInputModeGameOnly. Gameplay only; UMG ignored. - UI:
FInputModeUIOnly. UMG only; gameplay paused for input. - Game And UI:
FInputModeGameAndUI. Both receive; UMG takes priority on focus.
Cursor visibility is controlled separately by APlayerController::bShowMouseCursor.
Opening a Menu
void APlayerController::OpenMenu()
{
MenuWidget = CreateWidget<UUserWidget>(this, MenuClass);
MenuWidget->AddToViewport();
FInputModeGameAndUI Mode;
Mode.SetWidgetToFocus(MenuWidget->TakeWidget());
Mode.SetLockMouseToViewportBehavior(EMouseLockMode::DoNotLock);
SetInputMode(Mode);
bShowMouseCursor = true;
}
The cursor appears; UMG receives clicks; the rest of gameplay continues (paused or not depending on your design).
Closing a Menu
void APlayerController::CloseMenu()
{
if (MenuWidget) {
MenuWidget->RemoveFromParent();
MenuWidget = nullptr;
}
FSlateApplication::Get().ClearKeyboardFocus(EFocusCause::SetDirectly);
FInputModeGameOnly Mode;
SetInputMode(Mode);
bShowMouseCursor = false;
}
ClearKeyboardFocus is important — without it, the destroyed widget’s residual focus can trap input. Cursor hides; gameplay resumes; input goes to PlayerController.
Mouse Lock Behavior
For first-person games where the cursor should stay hidden and centered:
FInputModeGameOnly Mode;
SetInputMode(Mode);
bShowMouseCursor = false;
Unreal locks the mouse to the viewport center implicitly in fullscreen. In windowed, the OS handles cursor confinement; alt-tab may break the lock.
Pause Game Integration
For a pause menu that also pauses time:
UGameplayStatics::SetGamePaused(this, true);
SetInputMode(FInputModeUIOnly{...});
Time stops; only UMG input flows. Resume by SetGamePaused(false) + SetInputModeGameOnly.
Diagnosing
Print bShowMouseCursor and the current input mode name on toggle. Confirm both are what you expect at each state transition.
Verifying
Open and close the menu several times. Cursor and input should toggle predictably. No stuck cursors; no inputs going to the wrong handler.
“Input mode and cursor visibility are siblings, not children. Set them together every time you transition UI state.”
Wrap menu open/close in two helper functions on PlayerController — reuse for every menu so transitions stay consistent.