When backing out of Game on Android(h/w home button), and returns to play.. touch controls no longer work?(solved)

Hello, and thank you for your time.

Here are the basics of what I have going on -

  1. player object has a .js component
    that includes all player controls,
    which consist of tapping to move the
    player and several other features
    that swipe.
  2. There is also a pause menu object with a pauseGUI .js component
    that becomes
    active after a 3 finger touch.
  3. hardware back and menu buttons on
    android, are targeted to activate
    the pause menu as well.

Here is the issue in detail, please read to understand the issue.

On Android it’s common to multi-task… to back out by hitting “home” and checking something, and coming back to the game. Also, lets say i’m playing… put my phone down for 30sec and phone goes into “idle” (black screen)…I’m aware Android is built to pause the app in any of these occasions, which is great… and it’s great that it resumes after returning to play, however… it seems the “touch” controls no longer work when trying to resume.

Time is still running fine, particles are active… #1 and #2 as explained above do not work… but #3 does work. So the game is running, and specific things are active, but not everything? What’s weird is I’m still able to use the buttons active in OnGui(), restart levels, go back to main and select a new level… but once i get back into any level, no touch controls work. It almost seems it’s disabled the monobehavior Update() and I have to some how force enable all components? I’ve tried a ton of things onApplicationFocus or onApplicationPause… no luck. I’ve also tried dumbing down everything on the test build, to literally 1player object, and a bg texture to fly around… same issue, so i can’t see it to be a memory/ram issue. (2d game)

#My question is, Is breaking upon resuming gameplay a common Unity bug thing?
I’ve done a ton of research and found other Unity games on android market and downloaded them… when attempted to replicate, it actually just restarts the entire game and can’t properly resume. This leaves me to start believing that Unity is incapable of resuming a game after minimizing.

If not,
#Has anyone else had experience with dealing with this? if so, what did you do to avoid this?

If anyone needed to know, this is the basis of how I go about getting touch inputs for controls -

if( Input.touchCount == 1 )
  if( Input.GetTouch(0).fingerId == 0 )
    //code here

thanks guys.

It seems your touch code might rely on certain touch ids which it shouldn’t since touch ids are not guaranteed to start at 0. It’s actually a bug in Unity that touch ids which have been used before an “application sleep” are kind of “locked”. Anyways, you shouldn’t rely on the fact that touch ids starting at 0.

See this question for some more information :wink:

When a new touch occurs, so you get the touch state “Began”, you should remember the fingerID and use this stored ID whenever you work with touches. Once the touch has ended / canceled you should invalidate your variable by setting it to -1.

As an additional backup you should reset all your saved IDs when the touch count is 0.