Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

How to Eliminate or Compensate For Input Lag?

Discussion in 'Android' started by steveg2357, Dec 10, 2014.

  1. steveg2357

    steveg2357

    Joined:
    Aug 21, 2014
    Posts:
    34
    I am developing an app for multiple platforms with several objects moving on the screen. When I use a mouse on Windows, the app appears to be able to determine the correct object that was clicked on by the mouse. However, when I use a touchscreen on Android, the app often can't properly determine the correct object that was touched or it selects an incorrect object. It appears that there is a lag on Android and the problem may be due to Android queueing screen frames so that the touch input is out of sync with the object locations seen by the user when the screen was touched. Setting QualitySettings.maxQueuedFrames = 0 doesn't work on Android (since maxQueuedFrames is only implemented in Direct3D and not OpenGL). Is there some way to stop Android from queueing screen frames or a technique to compensate for the input lag?
     
  2. mdrotar

    mdrotar

    Joined:
    Aug 26, 2013
    Posts:
    377
    Most of the touch input lag comes from the hardware. The best you can do is try to compensate for it by calculating or tracking where the object was x milliseconds ago, where x is the amount of lag, and then using the lagged object positions instead of the real-time object positions when processing the touch event. But it's not that simple either because each Android device has a different amount of lag. It could be anywhere from ~50ms to ~200ms.
     
  3. steveg2357

    steveg2357

    Joined:
    Aug 21, 2014
    Posts:
    34
    My understanding is that the lag is not only device dependent, but it's not constant over time. I can probably compensate somewhat for slowly moving objects but I don't know of any viable techniques for quickly moving objects, especially when there are multiple objects on the screen. I doubt it, but is there any way to programmatically estimate the lag on a given device (i.e., without touching the screen)?
     
  4. mdrotar

    mdrotar

    Joined:
    Aug 26, 2013
    Posts:
    377
    I don't think that would be possible. For my purposes, it works well enough to compensate for 110ms on Android and 90ms on iOS since hits don't need terribly accurate. Then I also have a lookup table for specific devices that I can add to remotely for devices that are too far off the 110ms/90ms assumption. On iOS the lag is more consistent between devices and there are far fewer devices to consider. I don't think a general solution is possible for Android. I allow the user to manually set the lag value in the options menu. A user calibration has also been considered.