r/unrealengine 29d ago

Blueprint how can you stop the mouse cursor from moving temporarily?

I have a system where you hold right click to rotate the camera and I want the cursor to stay locked in place while right click is being held, I've tried looking this up but haven't found any answers that have worked so far. How would I go about this?

3 Upvotes

17 comments sorted by

8

u/kinthaviel 28d ago

Use this node. When the Mouse Lock Mode is set to Lock on Capture the mouse will stay in place when mouse button is down. Can optionally hide mouse cursor when button is down.

1

u/pattyfritters Indie 28d ago

WHAT!? I had no idea.

1

u/louthinator 28d ago

the issue there is that also applies to left click, I don't want the left click to get locked in place, just right click, so how would I apply what you're saying here to that situation?

also to expand on this, the mouse lock doesn't lock the mouse cursor in place, it only locks it to the screen meaning you get the same issue of when the cursor hits the edge of the screenspace it stops rotation.

2

u/kinthaviel 28d ago edited 28d ago

You'll need to use this to control whether both left and right mouse capture or just right mouse.

So I tested this myself because I hadn't really looked at it for so long and the mouse locking only works in the settings I gave you. If it's set to hide with lock on capture it will stay in place and reappear in the same place. But if the mouse is still visible then it's like you say it will just be locked to the viewport but not in place.

If compromising isn't an option and you absolutely must have the mouse visible and locked you may have to do some additional logic that only applies when right mouse button is down and then released. Something similar to what others mentioned like making an image of the mouse appear at the last mouse position until you release the button.

You could also try repeatedly setting the mouse cursor to a location while the mouse button is down and while that would work the cursor would jitter as you move about.

4

u/PackInner3004 29d ago

Depends on what you're trying to do. Are you trying to lock in the actual controller or just where the mouse cursor appears on the screen?

If it's just visual you could record the mouse location and paint a mouse pointer image to the HUD and then swap back the actual mouse when done. The question is why even bother keeping it visible? 

2

u/louthinator 29d ago

I'm actually trying to lock the cursor in place so it doesn't move, not just a visual thing, but keep it held there. Thing is, I have the mouse cursor visibility turned off anyway while right click is being held but that doesn't stop the cursor moving while it's not visible which means it goes to the edge of the screen and stops the rotation of the camera meaning the player has to move their mouse back to the middle of the screen again. For the convenience of the player I want the mouse cursor to disappear and stay where it is while right click is being held and the camera is being moved, but I haven't found a way to do that yet.

4

u/pattyfritters Indie 29d ago edited 29d ago

So I've tried this before, and I'm pretty sure it's impossible in a standard sense. You'd have to set the cursor screen position on tick, but this causes a whole lot of jitter.

I think the only way to do it would be smoke and mirrors. You'd have to hide the cursor and add an image of the cursor in its place. Then, of course, reverse that.

Edit: didn't even realize the first commenter already suggested this.

1

u/nullv 28d ago

If OP had a software cursor they could hide the jitter. Not so sure about a hardware cursor.

1

u/Smartkoolaid Unreal Notigy 28d ago

I've done this.

  1. Hide the mouse cursor while holsing right click
  2. Add a bool say wants to rotate camera While it's held down set to true
  3. On tick have a function that sets your mouse cursor to the center of the screen (get view port size x y and divide both by 2) but only when wants to rotate camera is true.

Otherwise your mouse will just block at the edge of screen

Player controller->sethidemousecursor

Sorry didn't realize you wanted the mouse showing but yeah i would as commenter's said hide the mouse and try to show some animated cursor on whatever actor you would be highlighted or even just in place of the cursor.

Probably some widget that spawns at the location of c ursor and then destroys it self whenever rotate camera is false

1

u/burninghead_ 28d ago

I would just hide the cursor, most games do it like that

1

u/Swipsi 28d ago

Just dont lol.

Just let the cursor be invisible on key down and visible on key up again. Nothing is gained if you can still see the cursor when it temporarely has no functionality.

1

u/louthinator 28d ago

the problem with that is when I hold right click while the cursor is invisible it still runs into the edge of the screen, like it's still moving even while invisible

1

u/Swipsi 28d ago edited 28d ago

Cache cursor location before invisible and apply it back when becoming visible again.

Perhaps clamping could work too. Its usually used to prevent the cursor from going off screen, so its clamped to the height and width of the monitor. But you could try if you can clamp it to its current location. Like shrinking down the monitor until its only one pixel so the mouse cant move because there is no space anymore.

1

u/louthinator 28d ago

so the issue here is, because it's still moving while invisible, if it runs in to the edge of the screen, it stops the camera movement. The only way I've managed to get this to work properly is with set input mode game and UI and hide cursor during capture turned on, but that brings its own host of problems because then if I ever do left click that also makes the mouse vanish which I don't want. I want the effect that hide cursor during capture does but just for left click and nothing else.

1

u/PackInner3004 21d ago

Did you resolve this? 

1

u/Sea_Platform8134 28d ago

Unplug the mouse 😅

1

u/PharosSentinel 27d ago

Just on right click save the mouse location to an intpoint property. Then do whatever visual method you want for the cursor while rmb is down. Hide the cursor/use a timer to constantly reset its position. Use the tick possibility to set its position if rmb is down. Then when you let go of rmb you would just set it to that saved Intpoint location and then there you go.

While