> ## Documentation Index
> Fetch the complete documentation index at: https://docs.nanoforge.eu/llms.txt
> Use this file to discover all available pages before exploring further.

# SceneLibrary

> The scene manager, exposed on Context.scenes.

Defined in: [modules/scene/src/scene.library.ts:49](https://github.com/NanoForge-dev/Engine/blob/ed8c7e0b33d17f8343c32659cf63ba4166a4fa53/modules/scene/src/scene.library.ts#L49)

The scene manager, exposed on `Context.scenes`.

## Remarks

Scene changes asked through `ctx.scenes` are queued, and made when no
system runs: before the tick's systems (for changes asked outside of
them, such as before `app.run()`) and right after them. The library runs
after every other one for that.

When the game stops, the loaded scenes and the vars are dropped without
calling `unload`: the other libraries are cleared by then.

## Example

```ts theme={null}
app.use(new SceneLibrary({ initial: MainMenu }));

// in a system
if (start) ctx.scenes.load(ctx, Level1, { params: { seed: 3 } });
```

## Extends

* `Library`

## Implements

* [`EditorAwareLibrary`](https://docs.nanoforge.eu/references/engine/3.0.0/editor-lib/interfaces/EditorAwareLibrary)

## Constructors

### Constructor

> **new SceneLibrary**(`_options?`): `SceneLibrary`

Defined in: [modules/scene/src/scene.library.ts:57](https://github.com/NanoForge-dev/Engine/blob/ed8c7e0b33d17f8343c32659cf63ba4166a4fa53/modules/scene/src/scene.library.ts#L57)

#### Parameters

##### \_options?

[`SceneLibraryOptions`](https://docs.nanoforge.eu/references/engine/3.0.0/scene/interfaces/SceneLibraryOptions) = `{}`

#### Returns

`SceneLibrary`

#### Overrides

`Library.constructor`

## Properties

### key

> `readonly` **key**: `"scenes"`

Defined in: [modules/scene/src/scene.library.ts:50](https://github.com/NanoForge-dev/Engine/blob/ed8c7e0b33d17f8343c32659cf63ba4166a4fa53/modules/scene/src/scene.library.ts#L50)

This library's identity: its slot on `Context`, its registry key, and
the identifier used to reference it in ordering relationships.

#### Overrides

`Library.key`

## Accessors

### manager

#### Get Signature

> **get** **manager**(): [`SceneManager`](https://docs.nanoforge.eu/references/engine/3.0.0/scene/classes/SceneManager)

Defined in: [modules/scene/src/scene.library.ts:122](https://github.com/NanoForge-dev/Engine/blob/ed8c7e0b33d17f8343c32659cf63ba4166a4fa53/modules/scene/src/scene.library.ts#L122)

The scene manager.

##### Returns

[`SceneManager`](https://docs.nanoforge.eu/references/engine/3.0.0/scene/classes/SceneManager)

***

### relationships

#### Get Signature

> **get** **relationships**(): `LibraryRelationships`

Defined in: packages/common/dist/index.d.ts:512

**`Internal`**

##### Returns

`LibraryRelationships`

#### Inherited from

`Library.relationships`

## Methods

### \_\_clear()

> **\_\_clear**(): `Promise`\<`void`>

Defined in: [modules/scene/src/scene.library.ts:99](https://github.com/NanoForge-dev/Engine/blob/ed8c7e0b33d17f8343c32659cf63ba4166a4fa53/modules/scene/src/scene.library.ts#L99)

Called once after the tick loop stops.

#### Returns

`Promise`\<`void`>

#### Overrides

`Library.__clear`

***

### \_\_editorInit()

> **\_\_editorInit**(`ctx`): `Promise`\<`void`>

Defined in: [modules/scene/src/scene.library.ts:69](https://github.com/NanoForge-dev/Engine/blob/ed8c7e0b33d17f8343c32659cf63ba4166a4fa53/modules/scene/src/scene.library.ts#L69)

Listens to the editor's scene commands (live mode).

#### Parameters

##### ctx

[`EditorInitContext`](https://docs.nanoforge.eu/references/engine/3.0.0/editor-lib/type-aliases/EditorInitContext)

#### Returns

`Promise`\<`void`>

#### Implementation of

[`EditorAwareLibrary`](https://docs.nanoforge.eu/references/engine/3.0.0/editor-lib/interfaces/EditorAwareLibrary).[`__editorInit`](https://docs.nanoforge.eu/references/engine/3.0.0/editor-lib/interfaces/EditorAwareLibrary#__editorinit)

***

### \_\_events()

> **\_\_events**(`ctx`): `Promise`\<`void`>

Defined in: [modules/scene/src/scene.library.ts:89](https://github.com/NanoForge-dev/Engine/blob/ed8c7e0b33d17f8343c32659cf63ba4166a4fa53/modules/scene/src/scene.library.ts#L89)

Called every tick, in run order, whether or not the tick loop is
paused — unlike `__run`. Use this for event/message draining that must
not be affected by pause (e.g. listening for the command that resumes
the loop), not for gameplay simulation.

#### Parameters

##### ctx

[`Context`](https://docs.nanoforge.eu/references/engine/3.0.0/ecs/index/interfaces/Context)

#### Returns

`Promise`\<`void`>

#### Overrides

`Library.__events`

***

### \_\_init()

> **\_\_init**(): `Promise`\<`void`>

Defined in: [modules/scene/src/scene.library.ts:61](https://github.com/NanoForge-dev/Engine/blob/ed8c7e0b33d17f8343c32659cf63ba4166a4fa53/modules/scene/src/scene.library.ts#L61)

Called once, in dependency order, before the tick loop starts.

#### Returns

`Promise`\<`void`>

#### Overrides

`Library.__init`

***

### \_\_run()

> **\_\_run**(`ctx`): `Promise`\<`void`>

Defined in: [modules/scene/src/scene.library.ts:94](https://github.com/NanoForge-dev/Engine/blob/ed8c7e0b33d17f8343c32659cf63ba4166a4fa53/modules/scene/src/scene.library.ts#L94)

Called every tick, in run order, while the tick loop is active and not paused.

#### Parameters

##### ctx

[`Context`](https://docs.nanoforge.eu/references/engine/3.0.0/ecs/index/interfaces/Context)

#### Returns

`Promise`\<`void`>

#### Overrides

`Library.__run`

***

### editorScenes()

> **editorScenes**(): [`EditorScenes`](https://docs.nanoforge.eu/references/engine/3.0.0/scene/interfaces/EditorScenes)

Defined in: [modules/scene/src/scene.library.ts:104](https://github.com/NanoForge-dev/Engine/blob/ed8c7e0b33d17f8343c32659cf63ba4166a4fa53/modules/scene/src/scene.library.ts#L104)

The loaded scenes and the vars, as the editor's `scenes` event carries them.

#### Returns

[`EditorScenes`](https://docs.nanoforge.eu/references/engine/3.0.0/scene/interfaces/EditorScenes)

***

### expose()

> **expose**(): [`ScenesContextApi`](https://docs.nanoforge.eu/references/engine/3.0.0/scene/interfaces/ScenesContextApi)

Defined in: [modules/scene/src/scene.library.ts:127](https://github.com/NanoForge-dev/Engine/blob/ed8c7e0b33d17f8343c32659cf63ba4166a4fa53/modules/scene/src/scene.library.ts#L127)

Returns this library's public contribution to `Context[this.key]`.

#### Returns

[`ScenesContextApi`](https://docs.nanoforge.eu/references/engine/3.0.0/scene/interfaces/ScenesContextApi)

#### Remarks

Return a plain object exposing only what game code should be able to
reach — never `this` — so internal state and lifecycle hooks never leak
onto `Context`. Libraries with nothing to expose (headless libraries)
can leave this unimplemented; they simply won't appear on `Context`.

#### Overrides

`Library.expose`

***

### throwNotInitializedError()

> `protected` **throwNotInitializedError**(): `never`

Defined in: packages/common/dist/index.d.ts:536

#### Returns

`never`

#### Inherited from

`Library.throwNotInitializedError`


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.