Custom PlayerController does not keep the cursor locked in middle?

I wanted to use a custom PlayerController to be able move the cursor freely and click on widgets with no problem, but now I want to bring the cursor back to the middle of screen. How do I do that?

I tried
SetInputMode(FInputModeUIOnly());
SetInputMode(FInputModeGameOnly());
but they do not lock the cursor to the middle (I’m still able to move the cursor freely).

I did my best searching but couldn’t find anything that worked for me.

APlayerController has SetMouseLocation(x, y) where x and y are in pixels. Get the game resolution, divide width and height by two, then plug the results in there.

edit: Wait, you want it to stay visible, but at the center of the screen, even when you move the mouse? Or do you just want to warp it to the center?

“Wait, you want it to stay visible, but at the center of the screen, even when you move the mouse?”
Yes that, like how the default PlayerController does (the one in Project Settings->Maps/Modes).

You can use SetMouseLocation function in event Tick, to force the cursor in the center of the screen.

I tried doing that but it did not feel very smooth and the cursor was bit shaky. Anyway, I’ve decided to use

SetInputMode(FInputModeGameOnly());
bShowMouseCursor = false;

with crosshair HUD display to fake that the cursor is the in middle. And that did the work for me. Thanks all though.