- Home /
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 -
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.
There is also a pause menu object with a pauseGUI .js component that becomes active after a 3 finger touch.
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?
'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.
Answer by Bunny83 · May 04, 2013 at 11:07 PM
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 ;)
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.
Awesome. $$anonymous$$akes complete sense. I'll re-visit the way I'm finding touch inputs in an hour so and let everyone know if this solves the problem. Sounds to be 99.9% correct. :)
Thanks alot Bunny83 :)
Little did i know it was a Unity bug.. what's weird is they actually have what I did as an actual example in the docs.. but they also have your suggestion in the docs as well... Good to know.
Confirmed, thank you so much. :)
Your answer
Follow this Question
Related Questions
Mutli-touch in android? 1 Answer
Changing Screen Orientation causes touch coordinates being wrong 0 Answers
How to drag an object along a path using touch controls in specific areas? 1 Answer
OnDrag methods not being called on Android in Unity 2018.3.5f1 3 Answers
How to tell if your android app has been put in the background? 1 Answer