Cant hide Mouse Cursor again

I got tired of waiting on this (don’t think we’re ever going to get a fix from Epic), so I’ve made a couple of engine changes. This worked for us but your mileage may vary. Obviously these are CODE changes, I don’t have anything useful to fix this from blueprints.

The first issue is that bShowMouseCursor on APlayerController doesn’t work. It looks like the cause of this lives in UGameViewportClient::GetCursor. What you need to do is disable/remove the first IF block in this method. This is what you should be left with:

EMouseCursor::Type UGameViewportClient::GetCursor(FViewport* InViewport, int32 X, int32 Y)
{
	if (GameInstance && GameInstance->GetFirstLocalPlayerController())
	{
		return GameInstance->GetFirstLocalPlayerController()->GetMouseCursor();
	}

	return FViewportClient::GetCursor(InViewport, X, Y);
}

Unfortunately, this by itself doesn’t do anything, because this code only runs when you move the mouse. If you’re like me and are trying to disable the mouse while a gamepad is active, you want this to reevaluate immediately. Fortunately, you can do that with a single call. I would do this whenever you modify bShowMouseCursor.

PlayerController->bShowMouseCursor = false;
FSlateApplication::Get().OnCursorSet();

The mouse should now respect the bShowMouseCursor flag and hide appropriately. However, we’re still not done, because if the cursor is above the window, it can still trigger mouse events despite being hidden. (Gamepad input changing menus would be a good cause of this.)

To fix this, you’ll want to find the method FSlateApplication::SynthesizeMouseMove. At the top of this method, add this block of code.

if (GetSoftwareCursorVis() == EVisibility::Hidden)
{
	return;
}

That should be it! The mouse should now hide and no longer trigger any events while the bShowMouseCursor is false. Hopefully this helps someone.

3 Likes