1

When receiving an incoming call for example, OnApplicationPause(false) is called, and when returning back to the app OnApplicationPause(true) is called. What's going to happen when returning? Do all my gameobjects on the scene run Start() again? If so that's bad because it'll reset everything to default in my case. I read different answers on different sites, I wonder why it's not clear.

SHAI
  • 789
  • 3
  • 10
  • 43

1 Answers1

4

No, Start() will not be called again after OnApplicationPause(true).

Start is called on the frame when a script is enabled just before any of the Update methods are called the first time.

Like the Awake function, Start is called exactly once in the lifetime of the script.

https://docs.unity3d.com/ScriptReference/MonoBehaviour.Start.html

Fredrik Widerberg
  • 3,068
  • 10
  • 30
  • 42
  • So what am I going to "lose" when `OnApplicationPause` is `true` again? If `Start()` isn't being called, would all my gamebjects keep their attached scripts preferences (variables) ? And their Transform position exactly like before pausing? Why do people serialize on `OnApplicationPause` if `Start()` isn't being called again. – SHAI Jun 13 '18 at 20:03
  • Not sure why you would "lose" anything. Your objects wouldnt looses any value or change positions just because OnApplicationPause() is called. People use OnApplicationPause() to know when the appliation gets paused. – Fredrik Widerberg Jun 13 '18 at 20:26
  • I meant to say that from what I understand- when a game pauses, we should serialize variables so we don't lose them when resuming (still not sure what exactly can get lost). Like that answer here: https://stackoverflow.com/questions/45847057/do-i-have-to-use-onpause-onstart-ondestroy – SHAI Jun 13 '18 at 20:50
  • 1
    To visualize this answer scroll down to scheme https://docs.unity3d.com/Manual/ExecutionOrder.html – obywan Jun 14 '18 at 07:35