I have a problem in my FPP C++ template (4.13). I couldn’t resolve using answers from answerhub so I post it here.
The game runs with cursor locked within viewport boundaries, but I need to click on viewport to be able to focus on the menu widget. At the same time the mouse cursor is not locked to the viewport anymore… WTF?
[RESOLVED by SetInputMode(FInputModeUIOnly) on BeginPlay()]
Another problem occurs after I click ‘New game’ which loads a new map - the cursor stays visible and has no focus on the FPP player controller.
Here’s my setup:
- Created blank level
- Created UMG menu widget blueprint (set to focusable)
- Set game mode to my custom C++ game mode
- Set player controller to my custom C++ player controller
- Created and added the widget to viewport in C++
- Started the game in editor as Standalone Game
AMainMenuGameMode::AMainMenuGameMode()
: Super()
{
PlayerControllerClass = AMainMenuPlayerController::StaticClass();
HUDClass = AMainMenuHUD::StaticClass();
static ConstructorHelpers::FClassFinder MainMenuWidgetBlueprint(TEXT("WidgetBlueprint'/Game/FirstPersonCPP/Blueprints/MainMenuWidget'"));
if (MainMenuWidgetBlueprint.Succeeded())
{
MainMenuWidgetClass = MainMenuWidgetBlueprint.Class;
}
else
{
MainMenuWidgetClass = nullptr;
}
}
void AMainMenuGameMode::BeginPlay()
{
Super::BeginPlay();
if (MainMenuWidgetClass != nullptr)
{
MainMenuWidget = CreateWidget(GetWorld(), MainMenuWidgetClass);
if (MainMenuWidget != nullptr)
{
MainMenuWidget->AddToViewport();
}
}
}
There is also a third problem when I want to show pause menu while playing TPP level. Menu widget shows up affter AddToViewport(), but the cursor stays invisible and I can’t focus on the pause menu widget.
void AGamePlayerController::BeginPlay()
{
Super::BeginPlay();
bShowMouseCursor = false;
SetInputMode(InputModeGameOnly);
}
void AGamePlayerController::ShowMenuCursor(TSharedPtr MenuWidgetPtr)
{
bShowMouseCursor = true;
SetInputMode(InputModeUIOnly);
InputModeUIOnly.SetWidgetToFocus(MenuWidgetPtr);
}
void AGamePlayerController::HideMenuCursor()
{
SetInputMode(InputModeGameOnly);
bShowMouseCursor = false;
}