Game Development Reference
In-Depth Information
Application focus and pausing
Three additional
MonoBehaviour
events are notable for causing confusion or surprise
about their operation. They are:
OnApplicationPause
,
OnApplicationFocus
,
and
OnApplicationQuit
.
OnApplicationQuit
is sent to all objects in the scene just before the game exits
but before the scene and its contents are effectively destroyed. If the game is being
tested in the editor, then
OnApplicationQuit
is called when playback is stopped.
Significantly, however,
OnApplicationQuit
may not be called for iOS devices,
which usually don't quit or exit applications but rather suspend them while users do
other things, which allows them to return and resume from where they left off. If you
need or want to receive
OnApplicationQuit
events on suspension, you'll need to
enable the relevant option from the
Player Settings
window. To access this, navigate
to
Edit
|
Project Settings
|
Player
from the application menu and then from the
Object Inspector, expand the
Other Settings
tab for the iOS builds and enable the
Exit on Suspend
checkbox, as shown in the following screenshot:
Enabling the exit on suspend option for iOS