Problem with Show/Hide Mouse Cursor on the Widgets

#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;

	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;

	FInputModeUIOnly inputSettings;

		UE_LOG(LogTemp, Warning, TEXT("player controller ok. setting input mode settings"));
		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?


This is the code I used to enable the mouse. Let me know if it works. Looking at your code, you’re trying to reuse the code to show which has got extra code that isn’t needed for the hide. In fact, the SetWidgetToFocus and SetLockMouseToViewportBehavior may be the cause of the issue.

  const FInputModeGameOnly InputModeOptions;
  PlayerController->SetInputMode( InputModeOptions );
  PlayerController->bShowMouseCursor = false;
1 Like

Thanks. I have had to start my project again as I ran into some problems/mess with my project.

I will soon get to the point again to add the menu (and hide the cursor etc). Once I get there I will try your suggestion and let you know if it worked.

Many thanks

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.

Privacy & Terms