Search Unity

Touch lag compared to normal Android SDK, is this a Unity3d performance issue??

Discussion in 'Scripting' started by celaeno, May 31, 2013.

  1. celaeno

    celaeno

    Joined:
    Jan 31, 2013
    Posts:
    64
    Hello, I made two simple line drawing application, the first in Unity3d and the second in the normale Android SDK to compare the difference on the touch input because i'm experiencing touch input lag on Unity3d.

    Below the code I show 2 images to show the difference. The first image is done with Unity3d, and you can see a gap when quickly swiping a 270 degrees circle. The second image shows the same circle swiped on the Android SDK application, there is no big gap between the touch points and also it feels quite a bit more fluent when swiping figures. Both were tested on a HTC One device, without Unity3d remote.

    Is this an Unity3d performance issue or am I doing something wrong here? I put the code here , but I can't figure out what's wrong with it. The line is drawn when the last touch has ended, not using SendMessage doesn;t make any difference. Also I had a frames per second counter, which varies from 58.0 to 65.0, so sometimes it comes below 60, don;t know if that may be a problem...


    Code (csharp):
    1.  
    2. function Update ()
    3. {
    4.     if(Input.touchCount == 1)
    5.     {
    6.          // touch on screen
    7.          if(Input.GetTouch(0).phase == TouchPhase.Began)
    8.          {
    9.             pos = Input.GetTouch(0).position;      
    10.             ray = Camera.main.ScreenPointToRay(pos);
    11.            
    12.              if (Physics.Raycast (ray, hit, 50) )
    13.                     hit.transform.gameObject.SendMessage("TouchBegan");
    14.          }
    15.          
    16.          
    17.          if(Input.GetTouch(0).phase == TouchPhase.Moved)
    18.          {
    19.            
    20.              pos = Input.GetTouch(0).position;     
    21.             // pos = Camera.main.ScreenToWorldPoint(pos);
    22.            hit.transform.gameObject.SendMessage("TouchMoved",pos);
    23.                    
    24.  
    25.          }
    26.  
    27.  
    28.  
    29.         if (Input.GetTouch(0).phase == TouchPhase.Ended || Input.GetTouch(0).phase == TouchPhase.Canceled)
    30.         {
    31.        
    32.             hit.transform.gameObject.SendMessage("TouchEnded");
    33.        
    34.         }
    35.     }
    36.  
    37. }
    38.  
     

    Attached Files:

    Last edited: May 31, 2013
  2. Cake

    Cake

    Joined:
    Jul 1, 2013
    Posts:
    15
    It might be worth testing this out on a JellyBean device. I don't know how Unity3D integrates with Android but if they use the Choreographer introduced in Android 4.1 these issues could be fixed.

    But yes, if the FPS is ~60 and the same logic works as expected with a simple Android app, it's an issue with Unity3Ds integration with Android. (Unless during that gap you touched the screen with a second finger. Remove your if (Input.touchCount == 1) ... perhaps you are looking for Input.GetTouch?)