How to fix a bug with UE5.1 which causes the mouse cursor to become hidden

I just tracked down the root of this bug, and it is pretty silly.

The issue stems from PIE and Editor sharing a common instance of FSlateUser, so when you use a GamePad in PIE, it switches the ActiveInputMode from ECommonInputType::MouseAndKeyboard to ECommonInputType::Gamepad, and hides the mouse in FCommonAnalogCursor::RefreshCursorVisibility()

From there, the call to SlateApp.SetPlatformCursorVisibility(false) ultimately calls FSlateUser::SetCursorVisibility which sets the bCanDrawCursor property to false.

If you then stop the PIE session WHILE USING THE GAMEPAD, then bCanDrawCursorwill remain false, and you may not have a cursor in the editor.

At this point, you can get it back by right clicking in a viewport and such, but THEN any time you begin a drag action (such as moving a node, connecting a wire, adding a UI element, etc.) that pesky bCanDrawCursorflag is STILL FALSE, and so when FSlateUser::ProcessCursorReplyis called, the second IF statement is false, so it immediately drops down to Cursor->SetType(EMouseCursor::None), and poof your mouse is gone AGAIN.

At the moment, I don’t see anything setting bCanDrawCursorback to true in the Editor itself, aside from running the game again, and using the mouse and keyboard to exit the game while the cursor is visible.

I imagine that a simple call to FSlateUser::SetCursorVisibility(true)when PIE is stopped would fix the issue, but I am currently using a vanilla version of UE5.

1 Like

And FWIW, there IS a CVar that you can set to avoid the cursor from getting hidden in PIE in the first place, and then it stays visible in the Editor as well:

CommonUI.AlwaysShowCursor 1

:backhand_index_pointing_up::backhand_index_pointing_up::backhand_index_pointing_up::backhand_index_pointing_up::backhand_index_pointing_up::backhand_index_pointing_up::backhand_index_pointing_up::backhand_index_pointing_up::backhand_index_pointing_up::backhand_index_pointing_up::backhand_index_pointing_up::backhand_index_pointing_up:

It won’t bring back your hidden cursor in the Editor directly, but the next time you run PIE (or if the command is used in PIE rather than the Editor, but either work) the mouse will always be visible in game, AND the Editor.

That CVar causes UCommonUIActionRouterBase::ShouldAlwaysShowCursor() to return true, and short circuits this logic that hides your mouse when using a gamepad in PIE:

const bool bShowCursor = bIsAnalogMovementEnabled || ActionRouter.ShouldAlwaysShowCursor() || ActiveInputMethod == ECommonInputType::MouseAndKeyboard;

Again, that is in FCommonAnalogCursor::RefreshCursorVisibility(), where the mouse is typically hidden in game when ActiveInputMethod is set to ECommonInputType::Gamepad