# SceneRegistry

Class · category: Graphics

Source: https://github.com/playcanvas/engine/blob/f059dc005842f76e052cdf44d8370c8c7ec475ac/src/framework/scene-registry.js#L56

Container for storing and loading of scenes. An instance of the registry is created on the
[AppBase](https://api.playcanvas.com/engine/classes/AppBase.md) object as [AppBase#scenes](https://api.playcanvas.com/engine/classes/AppBase.md#scenes).

## Constructors

### constructor

```ts
new SceneRegistry(app: AppBase)
```

Create a new SceneRegistry instance.

**Parameters**

- `app` ([`AppBase`](https://api.playcanvas.com/engine/classes/AppBase.md)): The application.

## Methods

### add

```ts
add(name: string, url: string): boolean
```

Add a new item to the scene registry.

**Parameters**

- `name` (`string`): The name of the scene.
- `url` (`string`): The url of the scene file.

**Returns** `boolean`: Returns true if the scene was successfully added to the registry, false otherwise.

### changeScene

```ts
changeScene(sceneItem: string | SceneRegistryItem, callback?: ChangeSceneCallback): void
```

Change to a new scene. Calling this function will load the scene data, delete all
entities and graph nodes under `app.root` and load the scene settings and hierarchy.

**Parameters**

- `sceneItem` (`string |` [`SceneRegistryItem`](https://api.playcanvas.com/engine/classes/SceneRegistryItem.md)): The scene item (which can be found with
  [find](https://api.playcanvas.com/engine/classes/SceneRegistry.md#find), URL of the scene file (e.g."scene_id.json") or name of the scene.
- `callback` ([`ChangeSceneCallback`](https://api.playcanvas.com/engine/types/ChangeSceneCallback.md), optional): The function to call after loading,
  passed (err, entity) where err is null if no errors occurred.

**Example**

```ts
app.scenes.changeScene("Scene Name", (err, entity) => {
    if (!err) {
        // success
    } else {
        // error
    }
});
```

### find

```ts
find(name: string): SceneRegistryItem | null
```

Find a Scene by name and return the [SceneRegistryItem](https://api.playcanvas.com/engine/classes/SceneRegistryItem.md).

**Parameters**

- `name` (`string`): The name of the scene.

**Returns** [`SceneRegistryItem`](https://api.playcanvas.com/engine/classes/SceneRegistryItem.md) `| null`: The stored data about a scene or null if no scene with
that name exists.

### findByUrl

```ts
findByUrl(url: string): SceneRegistryItem | null
```

Find a scene by the URL and return the [SceneRegistryItem](https://api.playcanvas.com/engine/classes/SceneRegistryItem.md).

**Parameters**

- `url` (`string`): The URL to search by.

**Returns** [`SceneRegistryItem`](https://api.playcanvas.com/engine/classes/SceneRegistryItem.md) `| null`: The stored data about a scene or null if no scene with
that URL exists.

### list

```ts
list(): SceneRegistryItem[]
```

Return the list of scene.

**Returns** [`SceneRegistryItem`](https://api.playcanvas.com/engine/classes/SceneRegistryItem.md)`[]`: All items in the registry.

### loadScene

```ts
loadScene(url: string, callback: LoadSceneCallback): void
```

Load the scene hierarchy and scene settings. This is an internal method used by the
[AppBase](https://api.playcanvas.com/engine/classes/AppBase.md).

**Parameters**

- `url` (`string`): The URL of the scene file.
- `callback` ([`LoadSceneCallback`](https://api.playcanvas.com/engine/types/LoadSceneCallback.md)): The function called after the settings are
  applied. Passed (err, scene) where err is null if no error occurred and scene is the
  [Scene](https://api.playcanvas.com/engine/classes/Scene.md).

### loadSceneData

```ts
loadSceneData(sceneItem: string | SceneRegistryItem, callback: LoadSceneDataCallback): void
```

Loads and stores the scene data to reduce the number of the network requests when the same
scenes are loaded multiple times. Can also be used to load data before calling
[loadSceneHierarchy](https://api.playcanvas.com/engine/classes/SceneRegistry.md#loadscenehierarchy) and [loadSceneSettings](https://api.playcanvas.com/engine/classes/SceneRegistry.md#loadscenesettings) to make scene loading quicker for
the user.

**Parameters**

- `sceneItem` (`string |` [`SceneRegistryItem`](https://api.playcanvas.com/engine/classes/SceneRegistryItem.md)): The scene item (which can be found with
  [find](https://api.playcanvas.com/engine/classes/SceneRegistry.md#find), URL of the scene file (e.g."scene_id.json") or name of the scene.
- `callback` ([`LoadSceneDataCallback`](https://api.playcanvas.com/engine/types/LoadSceneDataCallback.md)): The function to call after loading,
  passed (err, sceneItem) where err is null if no errors occurred.

**Example**

```ts
const sceneItem = app.scenes.find("Scene Name");
app.scenes.loadSceneData(sceneItem, (err, sceneItem) => {
    if (err) {
        // error
    }
});
```

### loadSceneHierarchy

```ts
loadSceneHierarchy(sceneItem: string | SceneRegistryItem, callback: LoadHierarchyCallback): void
```

Load a scene file, create and initialize the Entity hierarchy and add the hierarchy to the
application root Entity.

**Parameters**

- `sceneItem` (`string |` [`SceneRegistryItem`](https://api.playcanvas.com/engine/classes/SceneRegistryItem.md)): The scene item (which can be found with
  [find](https://api.playcanvas.com/engine/classes/SceneRegistry.md#find), URL of the scene file (e.g."scene_id.json") or name of the scene.
- `callback` ([`LoadHierarchyCallback`](https://api.playcanvas.com/engine/types/LoadHierarchyCallback.md)): The function to call after loading,
  passed (err, entity) where err is null if no errors occurred.

**Example**

```ts
const sceneItem = app.scenes.find("Scene Name");
app.scenes.loadSceneHierarchy(sceneItem, (err, entity) => {
    if (!err) {
        const e = app.root.find("My New Entity");
    } else {
        // error
    }
});
```

### loadSceneSettings

```ts
loadSceneSettings(sceneItem: string | SceneRegistryItem, callback: LoadSettingsCallback): void
```

Load a scene file and apply the scene settings to the current scene.

**Parameters**

- `sceneItem` (`string |` [`SceneRegistryItem`](https://api.playcanvas.com/engine/classes/SceneRegistryItem.md)): The scene item (which can be found with
  [find](https://api.playcanvas.com/engine/classes/SceneRegistry.md#find), URL of the scene file (e.g."scene_id.json") or name of the scene.
- `callback` ([`LoadSettingsCallback`](https://api.playcanvas.com/engine/types/LoadSettingsCallback.md)): The function called after the settings
  are applied. Passed (err) where err is null if no error occurred.

**Example**

```ts
const sceneItem = app.scenes.find("Scene Name");
app.scenes.loadSceneSettings(sceneItem, (err) => {
    if (!err) {
        // success
    } else {
        // error
    }
});
```

### remove

```ts
remove(name: string): void
```

Remove an item from the scene registry.

**Parameters**

- `name` (`string`): The name of the scene.

### unloadSceneData

```ts
unloadSceneData(sceneItem: string | SceneRegistryItem): void
```

Unloads scene data that has been loaded previously using [loadSceneData](https://api.playcanvas.com/engine/classes/SceneRegistry.md#loadscenedata).

**Parameters**

- `sceneItem` (`string |` [`SceneRegistryItem`](https://api.playcanvas.com/engine/classes/SceneRegistryItem.md)): The scene item (which can be found with
  [find](https://api.playcanvas.com/engine/classes/SceneRegistry.md#find) or URL of the scene file. Usually this will be "scene_id.json".

**Example**

```ts
const sceneItem = app.scenes.find("Scene Name");
app.scenes.unloadSceneData(sceneItem);
```
