BabylonJS/Babylon.js · error

No camera available for screenshot.

Error message

No camera available for screenshot.

What it means

Thrown by the 'screenshot' command when no camera could be resolved at all: no cameraUniqueId was given and both the frame-graph main camera (FrameGraphUtils.FindMainCamera) and scene.activeCamera are null/undefined. Rendering requires a camera, so the command aborts.

Source

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

                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;
                }

                if (!camera) {
                    throw new Error("No camera available for screenshot.");
                }

                const precision = args.precision !== undefined ? Number(args.precision) : 1;
                if (!Number.isFinite(precision) || precision <= 0) {
                    throw new Error("precision must be a finite number greater than 0.");
                }

                let width: number | undefined;
                if (args.width !== undefined) {
                    width = Number(args.width);
                    if (!Number.isFinite(width) || width <= 0 || !Number.isInteger(width)) {
                        throw new Error("width must be a finite positive integer.");
                    }
                }

                let height: number | undefined;
                if (args.height !== undefined) {
                    height = Number(args.height);

View on GitHub (pinned to 0592b347b8)

Solutions

  1. Add a camera to the scene (e.g. new ArcRotateCamera/FreeCamera) and/or assign scene.activeCamera.
  2. If using a frame graph, configure it so FrameGraphUtils.FindMainCamera can resolve a main camera.
  3. Pass an explicit cameraUniqueId of an existing camera to bypass auto-resolution.

Example fix

// before
await execute("screenshot", {}); // scene has no cameras
// after
const cam = new BABYLON.FreeCamera("cam", new BABYLON.Vector3(0, 5, -10), scene);
scene.activeCamera = cam;
await execute("screenshot", {});
Defensive patterns

Strategy: type-guard

Validate before calling

if (!scene.activeCamera && !scene.frameGraph) throw new Error("Screenshot needs a camera: set scene.activeCamera or pass cameraUniqueId.");

Type guard

function hasResolvableCamera(scene: { activeCamera: unknown; frameGraph: unknown; cameras: unknown[] }): boolean {
  return scene.activeCamera != null || scene.frameGraph != null || scene.cameras.length > 0;
}

Try / catch

try {
  await screenshot(args);
} catch (e) {
  if (e instanceof Error && e.message === "No camera available for screenshot.") {
    scene.activeCamera = scene.cameras[0] ?? createDefaultCamera(scene);
    return screenshot(args);
  }
  throw e;
}

Prevention

When it happens

Trigger: Executing screenshot on a scene with zero cameras, or where activeCamera was never assigned and there is no frame graph (or the frame graph has no main camera).

Common situations: Building the scene procedurally and forgetting to add a camera or set scene.activeCamera; clearing all cameras mid-session; using a custom render pipeline where FindMainCamera returns null.

Related errors


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