#include "SteamGameGameInstance.h"
#include "UObject/ConstructorHelpers.h"
#include "Blueprint/UserWidget.h"
#include "Components/Widget.h"
USteamGameGameInstance::USteamGameGameInstance(const FObjectInitializer& ObjectInitializer)
{
static ConstructorHelpers::FClassFinder<UUserWidget> MainMenuBP (TEXT("/Game/GUI/WBP_MainMenu"));
if(!ensure(MainMenuBP.Class!=nullptr)) return;
WBPClass_MainMenu=MainMenuBP.Class;
UE_LOG(LogTemp, Warning, TEXT("found class %s"), *WBPClass_MainMenu->GetName());
}
void USteamGameGameInstance::LoadMainMenu()
{
if(!ensure(WBPClass_MainMenu!=nullptr)) return;
UUserWidget* menu=CreateWidget<UUserWidget>(this, WBPClass_MainMenu);
if(!ensure(menu!=nullptr)) return;
menu->AddToViewport();
menu->bIsFocusable=true;
FInputModeUIOnly inputSettings;
inputSettings.SetWidgetToFocus(menu->TakeWidget());
inputSettings.SetLockMouseToViewportBehavior(EMouseLockMode::DoNotLock);
if(GetPrimaryPlayerController()!=nullptr)
{
UE_LOG(LogTemp, Warning, TEXT("player controller ok. setting input mode settings"));
GetPrimaryPlayerController()->SetInputMode(inputSettings);
GetPrimaryPlayerController()->bShowMouseCursor=false; //this doesnt seem to have an effect
}
}
This is my code. But as you can see the value for ShowMouseCursor=false
. But I can still see the mouse cursor!
I read in documentation that there are two objects controlling cursor visibility. And so setting false
in the PlayerController won’t always hide it (eg. when mouse is over a widget, the widget controls visiblity).
But I thought this was the reason we are using FInputModeUIOnly
settings type ?!?!?
Can anyone help me to understand what is wrong here. I wish to avoid using Blueprint to change these settings , I much prefer everything possible to be done in the C++ solution (as this is easy for me to transfer between my projects, I actually despise using Blueprint).
I guess I am asking, How can I hide/show the mouse cursor, when mousing over the widgets?
Thanks