3
\$\begingroup\$

Have been at this for 2 days straight trying different ways to solve this, and I can't.

I'm simply dragging around a UI panel using PointerDown and Drag events. I set the transform.localPosition inside the Drag handler. It works as expected, only problem is, the UI element seems to lag behind the cursor.

I created a GIF to show the issue in a build version to rule out the Editor.

Not sure how well you can see the issue, but the faster you move the cursor the worse it is.

Any ideas of what the issue is and how can I solve it?

Thanks

enter image description here

\$\endgroup\$

1 Answer 1

3
\$\begingroup\$

Your computer is using a hardware cursor, which is extremely fast at rendering the cursor.

Unity will be rendering the frame a few milliseconds slower than the cursor. All games have input lag to some degree. It takes time for the game engine to talk to the GPU, as well as process whatever CPU computations are needed per frame.

You can reduce input lag by disabling Vertical Sync via QualitySettings.vSyncCount = 0; (API reference here), though this may introduce screen tearing.

In short, don't worry about slight input lag like this. Whether you're aiming a gun with your mouse, moving an object, or even typing a character to display on the screen, there will be a slight delay – this is normal for games.

\$\endgroup\$
2
  • \$\begingroup\$ Thanks for the info, makes total sense. So I suppose once I implement a custom cursor, that should solve that issue? \$\endgroup\$ Sep 18, 2017 at 10:59
  • 1
    \$\begingroup\$ If you hide the hardware cursor and instead draw your own in-game sprite as a fake cursor, you'll find that the cursor will feel like it lags. Probably better to change the hardware cursor's icon via Cursor.SetCursor. Either way, it's impossible to completely eliminate the input lag. \$\endgroup\$ Sep 18, 2017 at 11:14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .