2

I've spent a couple of days messing with an input issue in a Unity3D app, where dragging a finger across a mobile device to drag a camera across the scene looked very choppy. At first I thought maybe it was a framerate issue but the framerate is steady. It turns out that on average about 50% of the time when I poll input during my Update() loop, I get the Touch but its deltaPosition is (0, 0), and it reports the same deltaTime as the touch that I grabbed from the previous frame.

So while dragging my finger across the screen (regardless of speed), I get something like:

Touch count: 1, touch deltaPosition: (0.5, 0.2), touch deltaTime: 0.0252472, frame: 1157

Touch count: 1, touch deltaPosition: (0.0, 0.0), touch deltaTime: 0.0252472, frame: 1158

Touch count: 1, touch deltaPosition: (0.8, 0.15), touch deltaTime: 0.0217239, frame: 1159

Touch count: 1, touch deltaPosition: (0.0, 0.0), touch deltaTime: 0.0217239, frame: 1160

Is there any reason why Unity would fail to get a deltaPosition from iOS each frame when my framerate is at or below 60fps?

Here's the gist of the code I'm using to test this:

public void Update()
{
    if (Input.touches.Length > 0)
    {
        Debug.LogWarning("Input touches found, number of touches: " + Input.touches.Length.ToString() + ", frame: " + Time.frameCount + ", frame deltaTime: " + Time.deltaTime);

        for (int i = 0; i < Input.touches.Length; ++i)
        {
            Touch touch = Input.GetTouch(i);
            Debug.LogWarning("Touch #" + i.ToString() + ", deltaPos: " + touch.deltaPosition + ", touch deltaTime: " + touch.deltaTime);
        }
    }
}

I created a new project in Unity just to test this issue, and basically if you query for a touch's deltaPosition at 60hz, you will occasionally get no deltaPosition every other frame. This is extremely easy to reproduce, I'm not sure how Unity hasn't fixed this. It seems to work for a period of time, sometimes seconds, sometimes a minute or two, and then input updates will only occur around 30hz, and that will happen for a few seconds to minutes.

EDIT: It looks as if this is likely a Unity bug: http://www.yaku.to/blog/2015/01/08/Unity-iOS-Touch-Input-Is-Broken-But-They-Say-Its-To-Be-Expected/

EDIT: More: touchesMoved called at irregular intervals

EDIT: And more: https://fogbugz.unity3d.com/default.asp?586933_i71f6o2c5c2i58r4

Community
  • 1
  • 1
Nic Foster
  • 2,864
  • 1
  • 27
  • 45

0 Answers0