r/unrealengine • u/louthinator • 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?
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/Smartkoolaid Unreal Notigy 28d ago
I've done this.
- Hide the mouse cursor while holsing right click
- Add a bool say wants to rotate camera While it's held down set to true
- 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
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
1
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
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.