Mouse position forced to center of screen when cursor not visible

In standalone/packaged builds of games in 4.14 when you set bShowMouseCursor on your PlayerController to false it forces the mouse cursor to the center of the screen. Digging through the code it looks like this was added to account for games with round window corners. However, my game hides the mouse cursor but uses its position to draw a decal on our landscape (so it actually exists inside the world instead of above it).

Is there any way of turning off or working around this behavior?

Hello ,

I tried reproducing what you mentioned but I’m not getting the same results. How are you going about checking where the mouse cursor is when you’re seeing that it is being locked to the middle of the screen? This actor blueprint is how I’m tracking it. I’m using this inside of the Top Down blueprint template.

The delay is just there so I can move the cursor around a bit to get an accurate representation before it goes invisible. Note that this does keep the decal visible that is following the cursor usually in the template.

Just to say, I believe I experience a related problem, when I set the DefaultViewportMouseLockMode to either Lock on Capture or Lock Always, GetMousePosition() returns the screen centre point effectively locking my camera. This happens in the Standalone window and in a build but not in the VR preview or PIE viewport, I noticed that if I set bShowMouseCursor to true GetMousePosition() works as it should, however I work in Stereo and cannot have the cursor visible…

Maybe that helps towards replicating it?

This worked fine in 4.13…

Here’s a blueprint for a player controller that I repro’d this with:

115172-locktest. (14.6 KB)

(the formatting on this image is breaking, it’s down below)

And my repro project: [MouseLockProject][1]

And just in case it wasn’t clear, this behavior only happens in Standalone or Packaged games, it works correctly in PIE

I’ve reproduced the problem, it ended up being the DefaultViewportMouseLockMode as Stickymango mentioned. Having that set to Do Not Lock avoids the issue but also means that your cursor will be able to leave the window which is not ideal.

I’ve also tested this on our latest internal build (equal to the Master branch on Github) and noticed that it isn’t occurring at all. This means that it was fixed at some point between 4.14 and our latest build. As such, I may not be putting a bug report in but I’m going to look into where this fix was made and see if it can be included in an upcoming hotfix. I’ll get back to you when I have more information.

Thank you both for your information. While this doesn’t occur in Master, I’ve placed a bug report in so that we can have this tracked and hopefully have it fixed for a 4.14 hotfix. You can track the bug report here: UE-38721.

Have a nice day!

I actually had changed the DefaultViewportMouseLockMode in my project but it seems that doesn’t matter after you set the input mode (this was happening after some UMG interaction, so I set the input mode to GameOnly once you’re done with that).

I pulled down the master branch for myself and it does look like that fixes the problem for my game. Thanks for taking a look.

I have this problem in 4.17! Mouse is locked to the center of screen when using Top Down Controller.

Hello raianlp,

You’ll need to give more information than that. An unedited Top Down template does not exhibit this issue. What have you done to change the template that caused this to occur?

Hi Mattew J!

Thanks for fast reply. I will describe my case as thorough as I can:

  1. I am loading different game level using seamless travel mechanism (LoadLevelAsync).

  2. Before new level loading starts InputMode is set to GameOnly. I show Widget_LoadingScreen and then do SetInputModeUIOnly and pass Widget_LoadingScreen as widget to focus and PlayerController as Controller. I do not lock mouse (Do Not Lock mode).

  3. As new level loads

  • I remove Widget_LoadingScreen (hide widget → set variable to nothing and call RemoveFromParent)
  • Spawn player using SpawnActor, possess it by player controller and then call SetInputModeGameOnly.

After that my mouse is stuck somewhere in the middle of the screen. Also GetMousePosition() and SetMousePosition() functions stop working (they just return the same XY again and again)

FIX1: Don’t do SetInputModeUIOnly. My assumption is that after new level loads mouse became locked to “broken/deleted” widget. Also I noticed (after digging UE4 sources) that SetInputModeGameOnly does NOT clear the mouse lock as two other functions do (I mean SetInputModeUIOnly and SetInputModeGameAndUIOnly). I think that is the problem.

FIX2: One can use SetInputModeGameAndUIOnly as new level loads but it seems hacky since I don’t want to explicitly use UI especially when there is SetInputModeGameOnly func is available)

I have to say that when I use SetShowMouseCursor(true) after SetInputModeGameOnly it works like a charm (it somehow releases mouse lock?)

A bit more on SetInputMode**** functions:

  1. As I said above previous mouse lock is not released when using SetInputModeGameOnly. I think It has to. Is that correct?

  2. I solved my problem using custom InputMode. Here is the ApplyInputMode function code:

    SlateOperations.ReleaseMouseCapture(); // CLEARS THE LOCK
    

    SlateOperations.ReleaseMouseLock(); // CLEARS THE LOCK
    SlateOperations.ClearUserFocus(); // CLEARS THE FOCUS

    SlateOperations.SetUserFocus(ViewportWidget.ToSharedRef());
    SlateOperations.LockMouseToWidget(ViewportWidget.ToSharedRef());

    SlateOperations.UseHighPrecisionMouseMovement(ViewportWidget.ToSharedRef());
    GameViewportClient.SetMouseLockMode(EMouseLockMode::DoNotLock);
    GameViewportClient.SetIgnoreInput(false);
    GameViewportClient.SetCaptureMouseOnClick(EMouseCaptureMode::NoCapture);

P.S. Here is source code link for SetInputModeGameOnly (my version releases the lock and does not capture mouse)
.com/EpicGames/UnrealEngine/blob/1d2c1e48bf49836a4fee1465be87ab3f27d5ae3a/Engine/Source/Runtime/Engine/Private/PlayerController.cpp#L4932

1 Like

I commented below. Please share your thoughts!

I have also encountered the same problem in 4.18 (on Linux Mint 18.3). You can easily reproduce the problem using the Top Down template: just add a BeginPlay event to the TopDownController with bShowMouseCursor=False node: Hide cursor posted by anonymous | blueprintUE | PasteBin For Unreal Engine 4