- Home /
Android: Touch Input Timeout Issue
We have a game on the Android Market and it is plagued by an issue with the touch input. In the game you have to hold the accelerator button to drive. The problem is that after 32 seconds (on my device) all touches get cancelled. This is a known issue as some reviewers have given us a bad review on the market for it. This page was all I could find on the internet about it:
http://www.xoomforums.com/forum/motorola-xoom-general-discussion/4638-touch-input-timeout.html
This means that after you have held down the accelerator for 32 seconds, it cuts off and you have to press it again to continue driving. I have tested this in a completely blank project so I know it's not our project at fault.
You can try it for yourself: Just dump this script in an empty scene, run it on Android and hold the screen for 32 seconds or so. If your phone has the same issue, the touch count will reset itself to zero, cancelling all active touches.
function OnGUI() { GUILayout.Label("Touch count " + Input.touchCount); }
Answer by Tseng · Dec 21, 2011 at 08:56 PM
Depends on how your code is implemented.
A good approach would be to to only react on certain touch phases. I.e. start accelerating if Input.touches[0].phase==TouchPhase.Began
and stop only at Input.touches[0].phase==TouchPhase.Ended
.
If an Input.touches[0].phase==TouchPhase.Canceled
happened (which probably happens when you time out), you have to decide what to do (i.e. notify the users that he has to retap, or simply ignore it and have the car continue to accelerate).
I tried something similar to this already but there were a couple of problems. The first you already mentioned is where the end phase is never fired when the touch is cancelled. The accelerator will essentially be "stuck" down until the player lifts their finger, touches the screen, then lifts their finger again.
The second problem with is that when the first touch is cancelled, any subsequent touch becomes the first touch. So I am holding the gas, it gets cancelled by the OS, I press another button which overwrites the first one and the gas gets cut off.
If this is a problem with the Android OS I am surprised there is not more information about it. I have done a lot of searching on Google and found nothing.
Answer by buffonomics · Feb 06, 2012 at 04:52 AM
if Input.touches[0].phase==TouchPhase.Canceled, intelligently persist the EFFECT of the touch using the coordinates of the canceled touch. Remove the effect of cancelled touch if total touchcount becomes > 1 as that means they have touched somewhere else.
The accelerator will essentially be "stuck" down in this state.
Well then I guess you have to incorporate this into your gameplay somehow. Acceleration lock = hyper speed. :)
I think I'm going to submit a bug report to Unity. I think this is actually a problem with the Android OS itself but there has to be some way to fix it.
I don't think Unity can do a thing about it if it's an Android OS bug. Unity is simply a layer on top the OS and reports to you what the OS tells it. You would be better served submiting a bug to Google :)