Version: 2020.1
LanguageEnglish
  • C#

MonoBehaviour.OnApplicationQuit()

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Switch to Manual

Description

Sent to all GameObjects before the application quits.

In the Editor, Unity calls this message when playmode is stopped.

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour { void OnApplicationQuit() { Debug.Log("Application ending after " + Time.time + " seconds"); } }

Note: iOS applications are usually suspended and do not quit. For iOS builds, enable the "Exit on Suspend" property in Player Settings to make the application quit and not suspend, otherwise you might not see this call. If you do not enable the "Exit on Suspend" property then you will see calls to OnApplicationPause instead.

On Windows Store Apps and Windows Phone 8.1 there is no application quit event. Use the OnApplicationFocus event when focusStatus equals false.
On WebGL it is not possible to implement OnApplicationQuit because of the way browser tabs close. For a workaround, see the Unity User Manual documentation on Interacting with browser scripting in WebGL.

Did you find this page useful? Please give it a rating: