Input.touches / Input.GetTouch(0) Lag?

Hi there,

I’m tinkering for the first time with the touch screens of the latest generation of iPad and iPodTouch devices. I have a simple test app with a gameObject’s position updated to match the x y location of the Input.GetTouch(0).position each Update().

When setting the position of the object there seems to be noticable lag between my finger position and the object’s position (with the object catching up over a couple of frame updates).

Games like Fruit Ninja appear to have snappier touch detection. Is this a known Unity issue, or do I need to do something arcane with the fixedUpdate frame rate stuff (which I haven’t dabbled yet)?

I get the same lag from Input.touches[0] or Input.GetTouch(0) (single finger touch, so I’m not reading off the wrong end of an array).

Changing Update() to LateUpdate() does not seem to help the problem. Also, fresh touches (taps) seem to update snappier than dragging touches.

Any advice iOS experts? Thanks :slight_smile:

Richard

What is the frame rate in your game? Laggy input is usually a sign of a slow game, not just slow input.

I was getting 30fps, and it seemed to have a 1 to 2 frame lag at least on a single finger drag. I did find out today about editing the obscure kFPS constant and now get 60fps which certainly helps obscure the delay, but it still feels some way off Fruit Ninja. (no I’m not cloning it, just an example :slight_smile: ). And a lot of advice on the forums seems to say lock to 30fps In any case to keep the fps constant.

There were some interesting code comments in the class where you edit the kFPS regarding input lag, but I’m not knowledgable enough to understand the details. Thanks for your attention so far.

Best practice is still using Input.GetTouch in an Update() call from what I could tell?

Thanks!

if you need low latency, you need to change the type of input handling loop in the xcode project away from the standard which is targeted at “continous smoothness with as little frame impact as possible”, you might want a more interupt alike behavior which priorizes input over “continue on next frame”

Also, I don’t see why GetTouch should be best practice. Best practice would be usage of Input.touches

Ahhh, so is there no way to do this within the Unity environment via C#?

Do I need to edit Objective C classes to bypass the lag?

Also wasn’t assuming GetTouch was best, more a question what should be best practice, so that was super helpful.

It seems the Unity Input class uses some interpolated smoothing that gives smooth swipes, but slight lag?

Many thanks for the insights!

Check out the docs. There are 2 interesting snippets in there that if true would definitely give an advantage to GetTouch:

It seems sill that one method would return a Touch that is different than the other but thats what the docs say…

it would especially sound silly that it allocates anything given it returns an array reference which is stored statically on a class and that by naming scheme is not a property but a real variable.

My sentiments exactly. Perhaps if there are any Unity employee trolls in the forum they could shed some light on the subject…