# OnExitingPlayModeAttribute

> Marks a static method as a callback to be invoked when exiting Play mode.

## Definition

* **Type:** Class
* **Namespace:** [UnityEngine](/engine/6000.5/script-reference/unityengine.md)
* **Assembly:** UnityEngine.CoreModule

```csharp
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
public sealed class OnExitingPlayModeAttribute : LifecycleAttributeBase
```

## Remarks

Methods marked with this attribute are called when exiting Play mode. This happens:

* When stopping Play mode in the Editor.
* Before code reload in Play mode (Editor only).
* Before application quit (Player only).

Use this callback to:

* Save Play mode state.
* Clean up runtime resources.
* Prepare for Edit mode or code reload.

This is a method attribute that can only be applied to `static` methods with no parameters and return type `void`.

**Important**: Due to differences in the way different platforms handle closing or navigating away from a running application, `[OnExitingPlayMode]` is subject to the same platform-specific limitations in built Players as [MonoBehaviour.OnApplicationQuit()](/engine/6000.5/script-reference/unityengine/monobehaviour/onapplicationquit.md). For more information, refer to the description for [MonoBehaviour.OnApplicationQuit()](/engine/6000.5/script-reference/unityengine/monobehaviour/onapplicationquit.md).

Additional Resources: [OnEnteringPlayModeAttribute](/engine/6000.5/script-reference/unityengine/onenteringplaymodeattribute.md), BeforeManagedObjectsBackupAttribute.

## Examples

```csharp
using UnityEngine;

public static partial class PlayModeManager
{
    [OnExitingPlayMode]
    static void OnPlayModeExited()
    {
        Debug.Log("Exiting Play mode");
    }
}
```

## Constructors

| Constructor                                                                                                    | Description                                                             |
| -------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------- |
| [OnExitingPlayModeAttribute()](/engine/6000.5/script-reference/unityengine/onexitingplaymodeattribute/ctor.md) | Marks the decorated static method to be invoked when exiting Play mode. |
