# API

**Assembly:** `Spark.Scenes` **Interface:** `IScenesPlugin` **Implementation:** `ScenesPlugin`

## Interface

```csharp
public interface IScenesPlugin
{
    List<SceneEntry> GetAllSceneEntries();
    SceneEntry GetSceneEntry(string sceneId);
    bool HasSceneEntry(string sceneId);
    void LoadScene(SceneEntry sceneEntry);
    void LoadSceneById(string sceneId);
    void LoadSceneByName(string sceneName);
}
```

## Methods

### GetAllSceneEntries

```csharp
List<SceneEntry> GetAllSceneEntries()
```

Returns all scene entries in the database.

### GetSceneEntry

```csharp
SceneEntry GetSceneEntry(string sceneId)
```

Returns the scene entry with the given ID, or `null` if not found.

### HasSceneEntry

```csharp
bool HasSceneEntry(string sceneId)
```

Returns `true` if a scene entry exists with the given ID.

### LoadScene / LoadSceneById / LoadSceneByName

```csharp
void LoadScene(SceneEntry sceneEntry)
void LoadSceneById(string sceneId)
void LoadSceneByName(string sceneName)
```

Loads a scene using the `SceneLoader` system. Triggers loading screen, publishes events, and repositions the player entity on completion.

## SceneEntry

Extends `SparkDatabaseEntry`. Defines a game scene.

| Field                  | Type          | Description                                |
| ---------------------- | ------------- | ------------------------------------------ |
| `sceneFileName`        | string        | Scene name as registered in Build Settings |
| `defaultSpawnPosition` | Vector3       | Where the player spawns                    |
| `defaultSpawnRotation` | Vector3       | Player facing direction (Euler angles)     |
| `loadingImages`        | List\<Sprite> | Images shown during loading                |

**Methods:**

```csharp
Vector3 GetDefaultSpawnPosition()
Quaternion GetDefaultSpawnRotation()
Sprite GetRandomLoadingImage()
bool HasLoadingImages()
string GetSceneFileName()
```

## Commands

| Command            | Fields                | Description           |
| ------------------ | --------------------- | --------------------- |
| `LoadSceneCommand` | `string SceneEntryId` | Requests a scene load |

## Events

### SceneLoadStartedEvent

Published when a scene begins loading.

| Property        | Type   | Description           |
| --------------- | ------ | --------------------- |
| `SceneEntryId`  | string | ID of the scene entry |
| `SceneFileName` | string | Scene file name       |

EventType: `"Scenes.LoadStarted"`

### SceneLoadCompletedEvent

Published when a scene finishes loading.

| Property        | Type   | Description           |
| --------------- | ------ | --------------------- |
| `SceneEntryId`  | string | ID of the scene entry |
| `SceneFileName` | string | Scene file name       |

EventType: `"Scenes.LoadCompleted"`

## SceneLoader

Static utility class that handles async scene loading with progress tracking. Integrates with `LoadingScreenManager` for visual feedback.

## Usage

```csharp
var scenesPlugin = Spark.GetPlugin<IScenesPlugin>();
if (scenesPlugin != null)
{
    // Load by entry
    SceneEntry dungeon = scenesPlugin.GetSceneEntry("dungeon_01");
    scenesPlugin.LoadScene(dungeon);

    // Load by ID
    scenesPlugin.LoadSceneById("town_01");

    // Load by name
    scenesPlugin.LoadSceneByName("MainMenu");
}

// Listen for scene load events
SparkEventBus.Subscribe<SceneLoadCompletedEvent>(this);

public bool Handle(SceneLoadCompletedEvent evt)
{
    Debug.Log($"Scene loaded: {evt.SceneFileName}");
    return false;
}
```


---

# 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://docs.sparkframework.dev/documentation/developer-guide/core-systems/scenes/api.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.
