Download

Lock Mouse to Viewport works only if called every Tick

A simple input action (on mouse click for example) to call a function to change the InputMode and lock mouse to viewport won’t lock the mouse to viewport.


FInputModeGameAndUI InputMode;
InputMode.SetLockMouseToViewport(true);
InputMode.SetHideCursorDuringCapture(false);
SetInputMode(InputMode);

However, if I call the SetInputMode continuously every Tick in the PlayerController, it works.


void APlayerController::PlayerTick(float DeltaTime)
{
    Super::PlayerTick(DeltaTime);

    FInputModeGameAndUI InputMode;
    InputMode.SetLockMouseToViewport(true);
    InputMode.SetHideCursorDuringCapture(false);
    SetInputMode(InputMode);
}

Engine version 4.12.5.

Bug? Calling it once won’t lock to viewport at all unless you keep calling it in Tick.

EDIT: found the reason why. it seems bShowMouseCursor == true will cause this to not work. However, if I set it to false, the cursor will lock to viewport correctly without having to use that Tick workaround. Seems like a bug.