BabylonJS/Babylon.js · error

No active scene.

Error message

No active scene.

What it means

Thrown by the 'screenshot' CLI command when sceneContext.currentScene is null/undefined. Screenshots are captured by rendering through the active scene's engine, so an active scene is a hard prerequisite. This guard runs before camera resolution and any rendering.

Source

Thrown at packages/dev/inspector-v2/src/services/cli/screenshotCommandService.ts:43

                    name: "width",
                    description: "Screenshot width in pixels. When set, uses custom size mode.",
                    required: false,
                },
                {
                    name: "height",
                    description: "Screenshot height in pixels. When set, uses custom size mode.",
                    required: false,
                },
                {
                    name: "precision",
                    description: "Resolution multiplier (e.g. 2 for double resolution). Defaults to 1.",
                    required: false,
                },
            ],
            executeAsync: async (args) => {
                const scene = sceneContext.currentScene;
                if (!scene) {
                    throw new Error("No active scene.");
                }

                const engine = scene.getEngine();

                // Resolve camera: explicit uniqueId, or active/frame-graph camera.
                let camera;
                if (args.cameraUniqueId) {
                    const cameraId = parseInt(args.cameraUniqueId, 10);
                    if (isNaN(cameraId)) {
                        throw new Error("cameraUniqueId must be a number.");
                    }
                    camera = scene.cameras.find((c) => c.uniqueId === cameraId);
                    if (!camera) {
                        throw new Error(`No camera found with uniqueId ${cameraId}.`);
                    }
                } else {
                    camera = scene.frameGraph ? FrameGraphUtils.FindMainCamera(scene.frameGraph) : scene.activeCamera;
                }

View on GitHub (pinned to 0592b347b8)

Solutions

  1. Ensure the scene is created and rendered at least once, then retry the screenshot command.
  2. In scripts, wait for a 'ready'/'first frame' signal before invoking screenshot.
  3. Verify the inspector was registered with the same sceneContext/engine the app renders with.

Example fix

// before
await execute("screenshot", {}); // scene not ready
// after
await waitForFirstRender();
await execute("screenshot", {});
Defensive patterns

Strategy: try-catch

Validate before calling

if (!sceneContext.currentScene) throw new Error("Cannot take screenshot: no active scene.");

Type guard

function sceneAvailable(ctx: { currentScene: unknown }): boolean { return ctx.currentScene != null; }

Try / catch

try {
  await screenshot(args);
} catch (e) {
  if (e instanceof Error && e.message === "No active scene.") {
    await waitForFirstRender();
    return screenshot(args); // one retry after readiness
  }
  throw e;
}

Prevention

When it happens

Trigger: Executing 'screenshot' before the app creates a scene, after scene disposal, or while the inspector's sceneContext is pointed at a context with no current scene.

Common situations: An automation agent taking a screenshot immediately after inspector startup before first render; scene rebuilt during hot-reload leaving currentScene null; attaching the inspector to the wrong engine instance.

Related errors


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