The ISceneEventListener is called by the SceneSwitcher when a scene is loaded or unloaded.
It must be added to the root object of your scene (that is being loaded) or on the same object as the SceneSwitcher
It can be used to e.g. smooth the transition between scenes or to load additional content when a scene is loaded.

import { ISceneEventListener } from "@needle-tools/engine";

// Add this component to the root object of a scene loaded by a SceneSwitcher or to the same object as the SceneSwitcher
export class MySceneListener implements ISceneEventListener {
async sceneOpened(sceneSwitcher: SceneSwitcher) {
console.log("Scene opened", sceneSwitcher.currentlyLoadedScene?.uri);
}
}
interface ISceneEventListener {
    sceneClosing(): Promise<void>;
    sceneOpened(sceneSwitcher: SceneSwitcher): Promise<void>;
}

Methods

  • Called before the scene is being removed (due to another scene being loaded)

    Returns Promise<void>

  • Called when the scene is loaded and added

    Parameters

    Returns Promise<void>