Unity UI Dragging (touch input) feels pretty slow on Android compared to other games?

Hey there.

When using an empty scene with only a camera, an UI canvas and a small image, together with the basic OnDrag event, the image is always lagging behind your input.

First I thought maybe the mobile phones are that laggy, but then I remembered that the many tiny games I played where you dragged some stuff around never felt this way. And we are talking about a Samsung s7 and s8 device here.

If you play some other drag and drop games not from unity they are absolutely accurate in dragging around stuff. But if you just try to do the same in unity it always lags behind (we are talking about several frames not just 1). Its not a lot, but you can definite feel a much higher slowness.

Is there any way to circumvent this problem? Any variable/setting/fix you could configure in Unity which I missed?

Thanks in advance,
Oliver

I’ve also had performance problems with Touch events on Android. I didn’t find any solution on forum so I was thinking about proper way to implement Touch and Mouse.
I do find very good video on this, maybe it can help to someone -

But this does not fix my problem, so I start to analyze what can make such lag. I do found the root cause - external library. I was using “Outline Effect” plugin from Asset store. It was introducing huge lag on Android. After disabling it everything goes really smooth. So you should consider asset store stuff also.

Hope this tips can help someone.

Most Android phones usually cannot have the detected touch position to be exactly under the finger unlike iOS unfortunately. You can check this with Developer Options > Input > Show Touches. It will show a white dot on the screen. You then try to drag a finger very fast and see how far between the white dot and your finger. My Xiaomi Mi A2 is around 1-2cm for moderately fast motion.

And then in Unity it would be impossible to catch up to the white dot since the dot was updated with OS’s drawing code (probably updated as often as input refresh rate, that could be more than 60FPS) while Unity has to update by frame rate (60 FPS/16.66ms) So your Unity object will still be lagging behind the white dot.

And then you update your Unity object with asking Input.touches. This API will need 1-2 frames latency from the actual touch the phone can report since it has to collect and process touch data before presenting them to you. Look at this recent video I made for Native Touch, I ask the yellow box on every Update() to follow the touch, but the red box to follow the latest native touch callbacks. The result is the red box can go ahead of the yellow box by 1 frame advantage. (Of course, still behind the white dot.)

Native Touch’s callback is almost the same as touch callbacks you can get from developing a native Android Studio project. Remember that Unity’s API is only 1-2 frames late from the callback, the improvement is at best it should not be more than 16.67ms - 33.33ms. If your touch lag feels like it is more than that I am afraid the problem might be somewhere else…

1 Like