BabylonJS/Babylon.js · error · Error

No scene available to load asset container to

Error message

No scene available to load asset container to

What it means

loadAssetContainerAsync requires a target Scene to attach pending data and build the AssetContainer against. Passing null/undefined for the scene parameter causes this throw before any loading starts.

Source

Thrown at packages/dev/core/src/Loading/sceneLoader.ts:1151

 * @param options an object that configures aspects of how the scene is loaded
 * @returns A promise that resolves when the scene is appended
 */
export async function appendSceneAsync(source: SceneSource, scene: Scene, options?: AppendOptions): Promise<void> {
    return await AppendSceneAsync(source, scene, options);
}

// This is the core implementation of load asset container
async function loadAssetContainerCoreAsync(
    rootUrl: string,
    sceneFilename: SceneSource = "",
    scene: Nullable<Scene> = EngineStore.LastCreatedScene,
    onProgress?: Nullable<(event: ISceneLoaderProgressEvent) => void>,
    pluginExtension?: Nullable<string>,
    name = "",
    pluginOptions: PluginOptions = {}
): Promise<AssetContainer> {
    if (!scene) {
        throw new Error("No scene available to load asset container to");
    }

    const fileInfo = GetFileInfo(rootUrl, sceneFilename);
    if (!fileInfo) {
        throw new Error("Cannot load file: a valid scene filename or root url was not provided.");
    }

    const loadingToken = {};
    scene.addPendingData(loadingToken);

    const progressHandler = wrapProgress(onProgress);

    try {
        const { plugin, data } = await loadDataAsync(fileInfo, scene, progressHandler, pluginExtension ?? null, name, pluginOptions);

        const asyncPlugin = toAsyncPlugin(plugin, fileInfo);
        if (!asyncPlugin.loadAssetContainerAsync) {
            throw createLoadError(fileInfo, loadAssetContainerNotSupportedMessage);

View on GitHub (pinned to 0592b347b8)

Solutions

  1. Create the engine and scene first, then pass the scene instance to LoadAssetContainerAsync
  2. Await engine/scene initialization before starting asset loading
  3. Guard the call: if (!scene) throw/log before invoking the loader

Example fix

// before
const container = await SceneLoader.LoadAssetContainerAsync(url, '', undefined);
// after
const scene = new Scene(engine);
const container = await SceneLoader.LoadAssetContainerAsync(url, '', scene);
Defensive patterns

Strategy: validation

Validate before calling

if (!scene) throw new Error('Scene must be created before loading asset containers');
const container = await SceneLoader.LoadAssetContainerAsync(rootUrl, filename, scene);

Type guard

const hasScene = (s: unknown): s is Scene => s instanceof Scene;

Try / catch

try {
  container = await SceneLoader.LoadAssetContainerAsync(url, '', scene);
} catch (e) {
  if (e instanceof Error && e.message.includes('No scene available')) {
    console.error('Scene was undefined when loading asset container');
  } else throw e;
}

Prevention

When it happens

Trigger: Calling SceneLoader.LoadAssetContainerAsync(rootUrl, filename, null) or omitting the scene argument so it resolves to undefined.

Common situations: Creating the container before initializing the engine/scene; a scene variable is undefined because engine init hasn't resolved or an earlier createScene call failed silently.

Related errors


AI-assisted analysis of BabylonJS/Babylon.js@0592b347b8 (2026-08-30). Data as JSON: /api/errors/30fc4ca1c1d1e346. Report an issue: GitHub.