# 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="/files/pgQRn7yEiQp5cZVJ80Gx" 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.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://tools.continis.io/superscenes/using-superscenes/defining-new-components.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
