BabylonJS/Babylon.js · error

No active scene.

Error message

No active scene.

What it means

MakeQueryCommand builds CLI query commands whose executeAsync first reads sceneContext.currentScene; if no scene is active (null/undefined) it throws 'No active scene.' because entity collections can only be enumerated against a live Scene. This happens when a bridge/CLI query command runs before a scene is created or after it has been disposed.

Source

Thrown at packages/dev/inspector-v2/src/services/cli/entityQueryService.ts:107

    };
}

function MinimalSummary(entity: { uniqueId: number; name?: string }): IEntitySummary {
    return {
        uniqueId: entity.uniqueId,
        name: entity.name,
    };
}

function MakeQueryCommand<T>(collection: IEntityCollection<T>, sceneContext: ISceneContext): BridgeCommandDescriptor {
    return {
        id: collection.id,
        description: collection.description,
        args: [UniqueIdArg],
        executeAsync: async (args) => {
            const scene = sceneContext.currentScene;
            if (!scene) {
                throw new Error("No active scene.");
            }

            const entities = collection.getEntities(scene);
            if (!entities) {
                return JSON.stringify([], null, 2);
            }

            if (!args.uniqueId) {
                return JSON.stringify(
                    entities.map((e) => collection.getSummary(e)),
                    null,
                    2
                );
            }

            const id = parseInt(args.uniqueId, 10);
            if (isNaN(id)) {
                throw new Error("uniqueId must be a number.");

View on GitHub (pinned to 0592b347b8)

Solutions

  1. Ensure a scene exists before running the command — wait for the engine/scene creation (e.g. engine.runRenderLoop or the scene-ready event) before issuing query commands.
  2. Guard the caller: check sceneContext.currentScene (or the engine's active scene) before invoking query-* commands and skip or queue them.
  3. If the scene was disposed, recreate it (new Scene(engine)) and re-run the query.
  4. In automation scripts, add a readiness poll that waits until the scene is available with a timeout.

Example fix

// before: command may run before scene exists
const result = await bridge.execute("query-meshes", {});

// after: wait for an active scene
async function waitForScene(sceneContext, timeoutMs = 5000) {
  const start = Date.now();
  while (!sceneContext.currentScene) {
    if (Date.now() - start > timeoutMs) throw new Error("Timed out waiting for active scene");
    await new Promise(r => setTimeout(r, 100));
  }
}
await waitForScene(sceneContext);
const result = await bridge.execute("query-meshes", {});
Defensive patterns

Strategy: validation

Validate before calling

function requireActiveScene(sceneContext) {
  const scene = sceneContext?.currentScene;
  if (!scene) throw new Error("Cannot run query: no active scene. Wait for scene creation first.");
  return scene;
}

Type guard

function hasActiveScene(sceneContext) {
  return Boolean(sceneContext && sceneContext.currentScene);
}

Try / catch

try {
  const result = await bridge.execute("query-meshes", {});
} catch (e) {
  if (e.message === "No active scene.") {
    console.warn("Scene not ready — deferring query until scene is created.");
    await waitForScene(sceneContext);
    // retry the command here
  } else {
    throw e;
  }
}

Prevention

When it happens

Trigger: Executing any registered 'query-*' bridge/CLI command (e.g. query-meshes, query-materials) via the CLI/bridge while sceneContext.currentScene is null: before the engine creates a scene, after scene disposal, or in a context where the inspector is attached but no scene was ever registered.

Common situations: Running CLI queries in the inspector immediately after page load before the playground scene finishes creating; executing commands against a disposed scene; automation/agent tooling invoking bridge commands without first ensuring a scene exists; headless or test setups that register CLI services without initializing a scene.

Related errors


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