How to make on-screen cursor which snaps to objects?

I want to make a cursor which acts like a regular cursor up until you hover it in an area of an object, after which it will go in the center of the object and stay there until sufficient mouse movement gets it out of the area.

At first I thought to use the Mouse input’s delta position to make my own cursor, but I found out quite quickly that since it’s not directly tied to mouse movement it can both go off-screen and become desynced.

It’s unusual to snap the cursor to an object. Usually when the cursor goes near an object then the object will be highlighted in some way and then when the user presses a mouse button the object is activated. Or if the object is to be dragged then it snaps to the cursor’s position.

The new input system can move the cursor with WarpCursorPosition.

If you’re using the old input system then you’ll need to replace the cursor and use Input.GetAxis to get the mouse delta.

Yea well, what I wanted to do is basically auto-aim. The game I am making features a lot of worldspace objects and I wanted to make it more accessible by helping the player interact with them, especially in motion. This might sound silly but I can’t really think of a better way to do that.

Also WarpCursorPosition moves the actual system cursor and I’d rather avoid that and only move the visual. So, what I am asking is more “How do I disconnect and reconnect attachment of my fake cursor to the mouse when I need to” than anything.

Like a lot of things in game dev it’s about separation of your visuals and data. Firstly, you need a fake cursor. You can do this easily with a UI overlay, and both uGUI and UI Toolkit can do this. Though rather than having faux cursor follow the actual cursor directly, you design it to be fed a position on the screen, and have another system(s) supply this position.

And that should be all it is, entirely visuals. What you’re actually auto-aiming onto should be entirely separate, and just feeds a position to the fake cursor when it is soft-locking onto something.