# Awake()

> Called when an instance of ScriptableObject is created.

## Definition

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

```csharp
public void Awake()
```

### Remarks

`Awake` is called when a new instance of a `ScriptableObject` is created, which happens in the following scenarios: \* At Editor startup, for all ScriptableObjects referenced in open scenes. \* On creation of a new ScriptableObject created as an asset via the [CreateAssetMenuAttribute](/engine/6000.5/script-reference/unityengine/createassetmenuattribute.md) in the Editor \* On instantiation of a ScriptableObject instantiated at runtime via [ScriptableObject.CreateInstance](/engine/6000.5/script-reference/unityengine/scriptableobject/createinstance.md) or by runtime loading of the asset. \* On first loading a scene which contains a reference to the ScriptableObject in the [Hierarchy window](/engine/6000.5/manual/unity-editor/editor-windows-views-reference/hierarchy-window/hierarchy.md), or on subsequent loads if the original instance has since been garbage collected. \* On first selection of a ScriptableObject in the [Project window](/engine/6000.5/manual/unity-editor/editor-windows-views-reference/project-view.md), or on subsequent selections if the original instance has since been garbage collected. **Note**: ScriptableObjects created as assets in Edit mode are not recreated on entering Play mode. To perform initialization work in a `ScriptableObject` on entering Play mode, use [ScriptableObject.OnEnable()](/engine/6000.5/script-reference/unityengine/scriptableobject/onenable.md) instead. An example is given below. This example has two scripts. The first shown is the [ScriptableObject](/engine/6000.5/script-reference/unityengine/scriptableobject.md) script. This implements code which is separate from [MonoBehaviour](/engine/6000.5/script-reference/unityengine/monobehaviour.md). The second is a small [MonoBehaviour](/engine/6000.5/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 OnDestroy()
    {
        Debug.Log("OnDestroy");
    }
}
```
