OnApplicationQuit()
Sent to all active GameObjects before the application quits.
Read time 1 minuteLast updated 5 days ago
Definition
- Type: Method
- Namespace: UnityEngine
public void OnApplicationQuit()
Remarks
In the Editor, Unity calls when exiting Play mode. It's called on all script components, even if the component is disabled. Unity doesn't send this message to inactive GameObjects. Platform-specific considerations: * iOS applications suspend rather than quit, so won't be called. Use MonoBehaviour.OnApplicationPause(bool) instead for handling app suspension and cleanup. * On Windows Store Apps and Windows Phone 8.1 there is no application quit event. Use the MonoBehaviour.OnApplicationFocus(bool) for handling app loss of focus. * The Web platform doesn't support because of the way browser tabs close. For a workaround, refer to Interaction with browser scripting in the manual. * If the user suspends your application on a mobile platform, the operating system can quit the application to free up resources. In this case, depending on the operating system, Unity might be unable to call this method. On mobile platforms, don't rely on this method to save the state of your application. Instead, consider every loss of application focus as the exit of the application and use MonoBehaviour.OnApplicationFocus(bool) to save any data.
OnApplicationQuitOnApplicationQuitOnApplicationQuitExamples
using UnityEngine;using System.Collections;public class ExampleClass : MonoBehaviour{ void OnApplicationQuit() { Debug.Log("Application ending after " + Time.time + " seconds"); }}