Engine version : 4.12.5 source build
Here’s how to reproduce this bug.
Create a simple Input function for a mouse click or key press that will call a function in the PlayerController class with this code to call SetInputMode with these settings
// Make mouse visible and locked to viewport
FInputModeGameAndUI InputMode;
InputMode.SetLockMouseToViewport(true);
InputMode.SetHideCursorDuringCapture(false);
SetInputMode(InputMode);
bShowMouseCursor = false;
bEnableClickEvents = true;
Here you can see I set InputMode to GameAndUI and set lock mouse to viewport to true, and then I set bShowMouseCursor to false.
Testing it in-game, your cursor is invisible, but moving it around will show you that it can’t get out of the viewport. (I implemented camera edge scrolling so I know when my cursor is on the edges since my camera moves).
Now if you change
bShowMouseCursor = true;
And test it in-game, you’ll see your cursor, but it won’t be locked to viewport.
However, a hack workaround for the cursor to lock to viewport while being bShowMouseCursor == true is to continuously SetInputMode in the Tick of the PlayerController and that will somehow lock the cursor to viewport.
Pretty sure this is a bug and I don’t think using a lame workaround like locking cursor to viewport every tick is the solution.