Search Unity

Custom Android input queue

Discussion in 'Android' started by bpdavis2006, May 23, 2018.

  1. bpdavis2006

    bpdavis2006

    Joined:
    Jun 3, 2013
    Posts:
    19
    The question of input lag concerning Android and Unity has been being asked for several years now, and I have yet to find a suitable answer to the question. The Unity staff have been strangely quiet on this issue. Other game engines, and I assume some Unity games, seem to cope extremely well with the lag. For instance, some driving games are especially responsive to monitoring drag events for steering the vehicle. My goal is to find out how these games and/or applications manage this seemingly impossible feat.

    It is unclear as to how often the hardware is polled for touches and drags. The accelerometer is polled at 60Hz, and its data is queued in the Input.acceleration variable. However, no other queueing seems to occur. My guess is that the touches and other associated data is acquired per frame. However, this does not account for drags that happen between frames or during the execution of one or more Update() methods. Therefore, data gets lost in the shuffle.

    Because this question has arisen so much, I'll try to ask it in a different light. Here goes.

    Would it be possible to write a custom input handler (e.x. in a separate thread, plugin, etc.) to queue events and avoid data loss? The reason for this is that I'm trying to, as best as is possible, record precise finger gestures (dragging in particular) for my application. My initial attempts have been to monitor Input.mousePosition, but the drag latency is unacceptable.

    I'll own up to the possibility that I'm going about this all wrong. Any suggestions would be most appreciated.
     
  2. bpdavis2006

    bpdavis2006

    Joined:
    Jun 3, 2013
    Posts:
    19
    I'm not quite ready to eat my words just yet..., but I decided to download a certain fruit slicing game that didn't suffer from the Android input lag issue... or so I thought. The latest version of the game (as of 5/23/2018) suffers from the same lag as what I'm dealing with.

    Is the hardware's technology at fault here? In other words, are the touch sensors themselves the source of the sometimes terrible lag? Does anyone know where the bottleneck lies? I'm truly interested in this problem. Could some sort of predictive algorithm, or perhaps a specialized dead reckoning algorithm, help with the lag issue?
     
  3. Yury-Habets

    Yury-Habets

    Unity Technologies

    Joined:
    Nov 18, 2013
    Posts:
    1,167
    We are using functions from the Android NDK to set the polling rate.
    ASensor_getMinDelay() and ASensorEventQueue_setEventRate().
    I think it results with SENSOR_DELAY_GAME (50 Hz).

    The input queues are being polled every frame. We rely on Android OS to deliver us all the input events.

    There was an issue with a laggy gyro on certain devices, I'm sure you can find the related thread on the forums.

    Hope that answers some of your questions.
     
  4. bpdavis2006

    bpdavis2006

    Joined:
    Jun 3, 2013
    Posts:
    19
    Thanks for that info! I appreciate the help. I'm wondering how (if?) can leverage this information.