Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by DDelapena · May 04, 2013 at 10:45 PM · androidtouch controlstouchcounthome button

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?

'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.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

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.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image DDelapena · May 04, 2013 at 11:31 PM 0
Share

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 :)

avatar image DDelapena · May 05, 2013 at 12:34 AM 0
Share

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

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

13 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Mutli-touch in android? 1 Answer

Touch Control for 2D Game 0 Answers

How to keep other activities on top after pressing the home button on Android? 0 Answers

Touch flip/slide misses 0 Answers

Short question: If my app runs without any problems on Android, should it run without any problems on iOS? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges