How does mouse capture/locking work?

I’ve been googling and poking through docs for 2 days. The only knobs I found are:

  • Project Settings → Capture Mouse On Launch, Viewport Mouse Capture Mode, Viewport Mouse Lock Mode
  • PlayerController → SetShowMouseCursor

Behavior I want:

  1. Middle mouse down, cursor disappears
  2. I drag the mouse around (it’s a flying camera that can pan and orbit)
  3. Middle mouse up, cursor appears in the same spot where it disappeared.

When I started playing around with these settings I could not make sense of the behavior.

Sometimes Mouse Motion/Mouse Button events were triggered, sometimes not. I haven’t been able to correlate what combinations of settings/mouse visibility affects this.

The docs don’t seem to describe things past the names I can already see.

What I’m looking for is a similar interface to Godot’s MouseMode enum. It makes the logic much simpler:

Input.MouseMode = middleButtonDown ? Input.MouseModeEnum.Captured : Input.MouseModeEnum.Visible;

If you can tell me how to do what I’m trying to do, great. I’m more interested in understanding how things work in Unreal.

1 Like

I think I’ve mapped out the behavior.

  • If mouse isn’t captured, no mouse movement events will trigger. So I have the capture mode set to “capture during mouse down”
  • If I hide the mouse with APlayerController::SetShowMouseCursor , the cursor will hit the edges of the viewport (or my monitor, depending on MouseLockMode )
  • Because of this, I started messing with FInputModeGameAndUI::SetHideCursorDuringCapture .
  • This gives me the behavior I want for the middle mouse, but now the other mouse buttons are affected.
  • I decide to change the SetHideCursorDuringCapture in response to the middle mouse click/release events. This seems to cause unpredictable behavior. I believe it’s affecting whether or not things get captured, but not sure.

It doesn’t really help me hide the mouse and lock it’s position in place, only while the middle button is down.

  • Is there no way to control mouse locking/capture/visibility in a more direct way? Still poking through engine source.

I’m assuming OP has moved on from this, but for anyone who ends up here in the future like I did due to similar struggles getting mouse capture/lock/camera motion/input modes to play together nicely (I’m also doing an RTS-style camera), I found this video super helpful in clarifying the expected functionalities:

He’s not doing the exact set up OP was looking for, but there’s a lot you could extrapolate to whatever your desired setup is. Also the first tutorial to bring these “Ignore Look Input” nodes to my attention:

image

As for OP’s goal of having the mouse cursor reappear at the same place it disappeared, I suppose you could finagle it manually by saving off the mouse position when you hide it, then resetting it when it reappears, using some combination of these:

image

1 Like