# OnDestroy()

> This function is called when the scriptable object will be destroyed.

## Definition

* **Type:** Method
* **Namespace:** [UnityEngine](/engine/6000.6/script-reference/unityengine.md)

```csharp
public void OnDestroy()
```

### Remarks

An example is given below. This example has two scripts. The first shown is the [ScriptableObject](/engine/6000.6/script-reference/unityengine/scriptableobject.md) script. This implements code which is separate from [MonoBehaviour](/engine/6000.6/script-reference/unityengine/monobehaviour.md). The second is a small [MonoBehaviour](/engine/6000.6/script-reference/unityengine/monobehaviour.md) related script which accesses values from the ScriptableObject script.

### Examples

```csharp

// A ScriptableObject example script.
// The A and B members implement features which
// are unrelated to MonoBehaviour.

using UnityEngine;

public class ScriptObj : ScriptableObject
{
    int a = 10;
    int[] b = new int[5] {0, 17, 34, 42, 67};

    public int A
    {
        get {return a; }
    }

    // return value in b array, or -1 if x is out-of-range
    public int B(int x)
    {
        if (x >= 0 && x < 5)
            return b[x];
        else
            return -1;
    }

    public void Awake()
    {
        Debug.Log("Awake");
    }

    public void OnEnable()
    {
        Debug.Log("OnEnable");
    }

    public void OnDisable()
    {
        Debug.Log("OnDisable");
    }

    public void OnDestroy()
    {
        Debug.Log("OnDestroy");
    }
}
```
