Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Touch Input Lag - Other games are fine

Discussion in 'Android' started by AlanGameDev, Apr 8, 2014.

  1. AlanGameDev

    AlanGameDev

    Joined:
    Jun 30, 2012
    Posts:
    437
    Hello there.

    I'm finishing my first platformer but when I test it on an Android device I can notice an input lag. I've made a minimal testing scene to make sure the problem is not related to framerate/overall performance.

    The other platformers from Google Play, for example Lep's World (cocos afaik) doesn't have the issue. :(

    I'm using getinput in update.

    Any ideas? Is it possible the other games run at higher fps or get inputs at higher frequency (independent from framerate?)

    Thank you in advance.
     
  2. Agent_007

    Agent_007

    Joined:
    Dec 18, 2011
    Posts:
    899
    Did you test with multiple devices?
     
  3. AlanGameDev

    AlanGameDev

    Joined:
    Jun 30, 2012
    Posts:
    437
    Well, I've tested on two devices (ICS and JB). One is considerably less powerful than the other but both runs pretty much any other game with no problems whatsoever. The framerate (OSD) on both is good.
     
  4. AlanGameDev

    AlanGameDev

    Joined:
    Jun 30, 2012
    Posts:
    437
    It seems to be a Unity issue because I've installed other Unity-based platformers and they have the same lag. :(

    The lag is not that bad but it can be an annoyance for my super-hard fast paced metal slug contra inspired oncoming game :(. I certainly would not like to play a game like that with that amount of input lag :(.

    Is there any way to measure the lag?

    I think these mobile devices already have a quite lot of 'hardware' lag, from the touch recognizing to the screen lag, now summed up to the Unity lag that's quite noticeable to me... perhaps because I'm used to playing on PC @ 60(+) fps.

    I'm using Unity for a 2D game mostly because I'm already used to it and I think it's always nice to use something that allows you to go for 3d easily and also publish across various platforms but the limitations/problems of it for 2d games are really starting to annoy me...
     
  5. arjeriababa

    arjeriababa

    Joined:
    Jan 26, 2014
    Posts:
    22
    Can you please tell which cell phone you are using?
     
  6. AlanGameDev

    AlanGameDev

    Joined:
    Jun 30, 2012
    Posts:
    437
    The problem appears on various phones, ranging from the Galaxy Pocket Plus to the Note 3, including other Samsungs (s2, s3) and the Motorolas (g, x, d1, d3). The lag is quite small and some people just don't notice it... however... hang on there guys because this weekend I'm gonna make a bucketful of tests to determine where is the problem and I'll keep you informed.
     
  7. AlanGameDev

    AlanGameDev

    Joined:
    Jun 30, 2012
    Posts:
    437
    It seems the problem is actually in Unity. I made a simple scene with only a camera, a quad and the following script:

    Code (csharp):
    1.  
    2. #pragma strict
    3.  
    4. var obj : Transform;
    5.  
    6. function Update () {
    7.     obj.position = Camera.main.ScreenToWorldPoint(Input.mousePosition) + Vector3(0,0,10);
    8. }
    9.  
    (obj is the quad)

    That I tested on two devices and when dragging the finger on the screen the quad is always some frames behind the touch position reported by android itself. Other apps like for example 'kivy touch tracer' doesn't have this problem.
     
  8. AlanGameDev

    AlanGameDev

    Joined:
    Jun 30, 2012
    Posts:
    437
    Okay, after extensive tests, I think the problem lies within Unity itself.

    I've modified the code to:
    Code (csharp):
    1.  
    2. #pragma strict
    3.  
    4. var obj : Transform;
    5.  
    6. function Update () {
    7.     if (Input.touches.Length) {
    8.             obj.position = Camera.main.ScreenToWorldPoint(Input.touches[0].position) + Vector3(0,0,10);
    9.         }
    10. }
    to make sure the problem wasn't the mouse stuff.

    It seems Unity is 3 times slower than Kivy (touch tracer), which also has a delay but it's much smaller, I'm attaching a picture showing the difference (sorry for the bad quality).

    $unityinput.png

    As you can see, the distance from the finger tip to the built-in visual feedback for touch is roughly the same, so the speed is also roughly the same. The Kivy output is much closer to the reported position than the object in Unity, in case of Unity the total latency (hardware+OS+App, which is already high imho) is roughly duplicated.

    My guess is Kivy is one frame behind and Unity three.
     
    Last edited: Apr 13, 2014
  9. nindim

    nindim

    Joined:
    Jan 22, 2013
    Posts:
    130
    Generally the hardware touch position on android is quite laggy compared to iOS devices I have tried, extra lag on top of that is a recipe for disaster.

    I'm seeing some pretty crazy touch lag on my Nexus 7 2013. It's way behind the hardware touch position, probably 3-4 frames at least, I also tried Kivy TouchTracer, and as you say it is probably only a frame behind.

    I'm considering writing a native plugin to get touch input specifically for android to see if it can be done any better, but I haven't gotten around to it yet, would be great if unity just fixed this...

    Have you submitted an official bug for this? If you do, I'd be happy to upvote it.
     
    Content1of_akind likes this.
  10. AlanGameDev

    AlanGameDev

    Joined:
    Jun 30, 2012
    Posts:
    437
    I think the problem is the screen resolution, it doesn't matter the phone specs, for example, the Galaxy Pocket Plus (1 core 800MHz, 512MB) has way less lag than any other device, it doesn't matter how powerful it is. It seems more resolution=more lag and vice-verse, the specs does't matter a lot. Perhaps it's because the touchscreen controller (the hardware thing) is slow or something. Of course the only thing that varies is the 'android' lag, the Unity lag is the same on all devices.

    Nope, I didn't submit a bug for this.
     
  11. PabloAM

    PabloAM

    Joined:
    Dec 25, 2012
    Posts:
    35
    Any news about this?

    I´m having the same problem with the lag with the version Unity 5.5.2 :(
     
  12. odysoftware

    odysoftware

    Joined:
    Jul 21, 2015
    Posts:
    84
    Sadly it seems that there is really a much higher delay in input processing on Android in Unity than it should be. Because several other games feel much more fluent - and even an empty scene in unity with the drag handler causes severe 100-300ms of movement lag. I guess many simply don't care - because it is not a deal breaker if you do not need to rely on accurate touch input controls - but if you have compared other games, I wonder why this doesn't get more attention.

    I mean this problem is still present in 2017 and even with high end smartphones like Samsung s8 etc. :(

    We can only hope that someone of the unity dev team will take a look at the lower level api access of unity and android to fix this.
     
  13. Bezzy

    Bezzy

    Joined:
    Apr 1, 2009
    Posts:
    75
    Yeah, I'm also still shocked at the latency. I'm using OnDrag calls, and I don't know if there's overhead with that since it's an event call, but yeah, it's really disappointing. I doubt it's a priority for manufacturers, which makes me never want to make a mobile game with any (game play critical) real time aspects ever again. And just generally it makes for nastier game feel. Oh well.
     
  14. Kalita2127

    Kalita2127

    Joined:
    Dec 6, 2014
    Posts:
    267
    Same here. I also experiencing delay like 100-200 ms between when I touch the virtual button and the output for the player movement. I'm using component event trigger from unity 5.6. I already checked all the common possibilities of performance issue from avoid call Find script per frame, static / dynamic batching, unnecessary loops, set quality settings as low as possible without reducing texture quality, avoid using LINQ. I'm using Samsung Note 2.
    Is there really no solution for this ? :( Will this issue remains forever ?
     
  15. Carbon-Code

    Carbon-Code

    Joined:
    Jan 9, 2015
    Posts:
    2
    Any update/solution to this problem? I have exact same issue on multiple devices using Unity 2017.3
     
    m_hakozaki likes this.
  16. odysoftware

    odysoftware

    Joined:
    Jul 21, 2015
    Posts:
    84
    Sadly no I guess they don't care - due to the fact that many accept this lag as normal and don't even recognise it. But I think too that the lag is too high and I wish they would investigate this and try to make it better to give the games a more responsive feeling.
     
  17. pertz

    pertz

    Joined:
    Jan 8, 2015
    Posts:
    106
    I have just ported my game (10M+ downloads) from an old engine to Unity and am rolling out the update this week, and I have been receiving hundreds (literally) of bad reviews due to the touch lag.

    After all possible optimizations I could think of I thought "maybe it's caused by Unity itself", so I Googled and got on this thread, and sadly there doesnt seem to have any solution...
     
    R3fr4ct0r and Antonio_Ketch like this.
  18. Ex34

    Ex34

    Joined:
    Aug 11, 2015
    Posts:
    1
    Hi, i have been searching internet and also found this thread that solve nothing. If you create simple flappy bird game in unity and export it, it has obvious touch lag. I have tried many other games and no lag at all or very small. So unity team really wont pay attention to this, because they go and trying to be better than unreal . This sucks
     
    R3fr4ct0r and Antonio_Ketch like this.
  19. Antonio_Ketch

    Antonio_Ketch

    Joined:
    Nov 3, 2014
    Posts:
    11
    I got same issue. Are there any feedback about this to vote? If it's enough votes, Unity team will take a look into this issue.
     
  20. 5argon

    5argon

    Joined:
    Jun 10, 2013
    Posts:
    1,554
    Most Android phones usually cannot have the detected touch position to be exactly under the finger unlike iOS unfortunately. I noticed that @AlanGameDev is already using the touch tracer Kivy, but Android's stock Developer Options > Input > Show Touches should be similar to show a white dot tracer 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.

    I don't know how Kivy compares to Android's touch tracer but I will assume it is similar that they draw the dot outside of Unity's game loop. And then that means 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, every 16.66ms) So your Unity object will still be lagging behind the white dot. I think this picture is correct in that Unity can never catch up to the touch debugger.

    With knowing that, Unity's touch has a bit more latency than what's possible with native Android app. 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. (While in native Android/iOS development, the touches are returned in the form of callbacks as soon as possible not by polling the API in-frame like Unity)

    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 even though both are updated in exactly the same
    Update()
    code. (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 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... (Like what @Ali_Akbar_Montazeri said 100-200ms, the number does not sounds like what touch latency Unity adds on top of native callbacks)
     
    shashKing, CanisLupus and Phoenix116 like this.
  21. brinaxvert

    brinaxvert

    Joined:
    Oct 13, 2020
    Posts:
    1
    I had the same problem,
    In my game there is a button to make the player jump and the lag whas like 100ms or but then i noticed that there wasn't that lag on pc with keyboard, so i discorver that Button.Onclick is called after the button is released so i make that my player jump when isClicked is true and that makes the player jump imediatly when the button is clicked
     
    vsapozhkov likes this.