# Defining new components

The first step to using SuperScenes is to create your own Scene Component types, as SuperScenes doesn't come with pre-made components out of the box.

{% hint style="info" %}
You will, however, find example components as part of the Package Samples in the Package Manager.
{% endhint %}

## Creating a new type

To create a new type, simply create a new class and implement the base abstract class `SceneComponent`. Then, add any data you need the component to hold.

For instance, a simple component that describes how enemy waves are spawn in a certain scene, could look like this:

```csharp
public class EnemyWaveData : SceneComponent
{
    public int numberOfEnemies;
    public int difficultyLevel;
}
```

Scene Components can hold any serializable type, and can hold them in `List<T>` or arrays.

You can store references to other Scenes, and to any other asset type like ScriptableObjects, Prefabs, etc. You can also store references to components present on Prefabs.

{% hint style="warning" %}
References to objects in the scene are not possible. This is a general Unity limitation.

To get a reference to an object in the scene, find it at runtime when the scene is loaded using some other method, like for instance `GameObject.Find()` or `Object.FindFirstObjectByType()`.
{% endhint %}

### SceneComponent script template

You can easily create a new Scene Component by just right-clicking in the Project view, and choosing **Create > SuperScenes > New Scene Component**.

<figure><img src="https://2245449607-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FyjkSLF6oFgX9nrUtKrLR%2Fuploads%2FDixDl5098zp4tZVmhrBh%2FNewComponentFromTemplate.png?alt=media&#x26;token=9dd7b19b-d90c-48e8-8854-c6e854a28f91" alt="" width="233"><figcaption></figcaption></figure>

Very much like it happens for a regular MonoBehaviour with `Start` and `Update`, the script generated will contain a pre-made template for a functioning Scene Component, so you'll get a head-start.

## OnSceneLoaded / OnSceneUnloaded

Scene Components can also run logic. For instance:

```csharp
public class EnemyWaveData : SceneComponent
{
    public AudioManagerSO audioManager;
    public AudioClip backgroundMusicTrack;
    
    public void override OnSceneLoaded()
    {
        audioManager.Play(backgroundMusicTrack);
    }
}
```

In this example, we override the `OnSceneLoaded()` method from the `SceneComponent` base class. When this scene is loaded, the code will execute and the `AudioManagerSO` ScriptableObject will play the referenced `AudioClip`.

`SceneComponent` provides both `OnSceneLoaded` and `OnSceneUnloaded` methods.
