Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by Dragonrider-Liu · Mar 05, 2018 at 04:33 PM · android2dscripting problemmobilemobileoptimization

Objects jump/warp for a little distance after regain the focus in Android

Hello, I met this problem for some time. The GameObjects is set to start a random movement by give their rigidbody2D a velocity in Start().

However, if I switch to the multi-app or say running-app page, and refocus to the game, they warp for a little distance. And according to the Time.time, the game time also past almost one second.

Here are two mp4s. I don't know if they are clear enough, I edited the first one to show the problem in 0.5 speed, and in the end a 0.25 replay for the key part, you can keep eyes on one of the moving GameObjects to see the warp, and pay a attention of the time text in another round.

The first text is Time.time*100+Time.deltatime*10000,

2nd counter for OnApplicationPause and OnApplicationFocus,

3rd I used this to find the order of execution of the two events in different situation,

4th deltatime between each event fired(P-pause, F-focus, D-Defocus).

If this description is too messy, you can read the scripts in the end of this question. According to the deltatime text, it seems no game time between the lost focus and regain focus. And for standalone build, the GameObjects work smoothly on my PC without this problem while I switch between different windows.

So, is this a problem only present in android? And since no problem for PC, it indicates no problem in scripts or settings of the game? And, no "solution" for it?

well, looks ugly, I admit.

alt text

key part with slower speed

full test show

The codes:

 //Codes not directly related to this issue is ignored.
 public class script : MonoBehaviour
 {
     public GameObject[] Roller;
     public Text TimeText;
     public Text PauseText;  //To see how many times the events were fired
     private int pause=0;
     private int focus = 0;
     private int defocus = 0;
     private bool isPause = true;
     public Text Order; //To show the sequence of events
     public Text Delta;  // To show game deltatime between event.
     float timer;
 
 void Start ()
 {
 PauseText.text = "Paused Times: " + pause + "  " + "Focused Times: " + focus + "  DeFocus Times: " + defocus;
 Order.text="";Delta.text="";timer=0f;
 }
 
     void Update ()
     {
         TimeText.text = "Time passed*100: " + (int)(Time.time*100) + "  " + "DeltaTime*10000:" + (int) (Time.deltaTime * 10000);
         PauseText.text = "Paused Times: " + pause + "  " + "Focused Times: " + focus + "  DeFocus Times: " + defocus;
 }
 
     private void OnApplicationPause(bool pauseStatus)
     {
         if (pauseStatus)
         {
             pause++;
         }
         Order.text=Order.text+"PauseCalled ";
         Delta.text=Delta.text+" P"+(int)((Time.time-timer)*10000);
         timer=Time.time;
     }
 
     private void OnApplicationFocus(bool hasFocus)
     {
         if (hasFocus)
         {
             focus++;Order.text=Order.text+"FocusCalled ";Delta.text=Delta.text+" F"+(int)((Time.time-timer)*10000);Time.timeScale=1;
         }
         else 
         {
             defocus++;Order.text=Order.text+"DeFocusCalled ";Delta.text=Delta.text+" D"+(int)((Time.time-timer)*10000);Time.timeScale=0;
         }
         timer=Time.time;
     }
 }


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

0 Replies

· Add your reply
  • Sort: 

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

330 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 avatar image avatar image avatar image avatar image avatar image

Related Questions

Is Collider 2D and OnMouseDown a good combination for mobile? 0 Answers

Is It Bad to be Tired of my Own Mobile Game? 1 Answer

Android apk lags on all devices exept of mine 0 Answers

Failed Re pack resources Unity Android 0 Answers

Mobile bloom kills performance 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