- Home /
Do I have to use onPause/onStart/onDestroy
I'm developing a puzzle game in Unity, when I exit my game to the home screen and return back- the game continues from the same spot and it seems to be fine (without overriding onPause/onStart), am I missing something? Do I need to save variables when exit? What do people usually save? I'm afraid to have bugs in the future.
Answer by pslattery · Aug 23, 2017 at 06:45 PM
So it sounds like you're developing for mobile platforms. Different OSes behave slightly differently but the principles are the same.
When an app loses focus, the OS preserves any memory its currently using, until another, currently active app, requests more memory that the OS has free, at which point the OS starts unloading active memory from apps not in focus to devote resources to the active app.
This is why, when you simply exit to the home screen and return, everything seems fine. But if you try opening a few other games and playing for a bit, I'd expect that eventually you'll see your game just relaunch and you'll lose any state info about the previous session.
This is why, if session data is important, to save some of that data onPause/onApplicationFocus etc. This way, when the app is reloaded mid-session, you can recover smoothly.
If you look search for it, I'm pretty sure Android and iOS both have guidelines for how to handle losing focus in games on each platform.
Your answer
Follow this Question
Related Questions
Is there anyway to consume events so OnMouse events don't fire on objects with lower Z? 1 Answer
Call AddListener on sibling components from MonoBehaviour.Reset 0 Answers
Can a function derived from MonoBehavior subscribe to a static delegate? 1 Answer
Does calling Destroy() on a GameObject/MonoBehavior drop references to any event listeners? 1 Answer
Events fired from Notification Center or Task Manager opening? 0 Answers