BabylonJS/Babylon.js · error

No camera defined

Error message

No camera defined

What it means

Scene.render() resolves which camera(s) to render through. If scene.activeCameras (multi-camera array) is empty/undefined and scene.activeCamera is also falsy, there is no camera to process sub-cameras with, so the scene throws 'No camera defined'. Babylon requires at least one active camera to compute view/projection matrices for a frame.

Source

Thrown at packages/dev/core/src/scene.pure.ts:5699

                step.action();
            }

            // Clear
            this._clearFrameBuffer(this.activeCamera);

            // Collects render targets from external components.
            for (const step of this._gatherRenderTargetsStage) {
                step.action(this._renderTargets);
            }

            // Multi-cameras?
            if (this.activeCameras && this.activeCameras.length > 0) {
                for (let cameraIndex = 0; cameraIndex < this.activeCameras.length; cameraIndex++) {
                    this._processSubCameras(this.activeCameras[cameraIndex], cameraIndex > 0);
                }
            } else {
                if (!this.activeCamera) {
                    throw new Error("No camera defined");
                }

                this._processSubCameras(this.activeCamera, !!this.activeCamera.outputRenderTarget);
            }
        }

        // Intersection checks
        this._checkIntersections();

        // Executes the after render stage actions.
        for (const step of this._afterRenderStage) {
            step.action();
        }

        // After render
        if (this.afterRender) {
            this.afterRender();
        }

View on GitHub (pinned to 0592b347b8)

Solutions

  1. Create a camera and assign it: scene.activeCamera = new FreeCamera(...) (or pass it as 4th arg to the constructor)
  2. If the camera was disposed, re-create/re-assign before the next render call
  3. For multi-camera setups, ensure activeCameras has entries or fall back to setting activeCamera
  4. Pause/skip scene.render() when no camera is available instead of calling it unconditionally

Example fix

// before
const scene = new Scene(engine);
engine.runRenderLoop(() => scene.render()); // no camera
// after
const scene = new Scene(engine);
scene.activeCamera = new FreeCamera('camera', new Vector3(0, 5, -10), scene);
engine.runRenderLoop(() => scene.render());
Defensive patterns

Strategy: validation

Validate before calling

if (!scene.activeCamera && !(scene.activeCameras && scene.activeCameras.length > 0)) {
  scene.activeCamera = new BABYLON.FreeCamera('default', new BABYLON.Vector3(0, 5, -10), scene);
}
scene.render();

Type guard

function sceneHasCamera(scene: BABYLON.Scene): boolean {
  return !!scene.activeCamera || (!!scene.activeCameras && scene.activeCameras.length > 0);
}

Try / catch

try {
  scene.render();
} catch (e) {
  if (e instanceof Error && e.message === 'No camera defined') {
    scene.activeCamera = createDefaultCamera(scene); // then re-render
  } else { throw e; }
}

Prevention

When it happens

Trigger: Calling scene.render() (directly or via engine.runRenderLoop) when the scene has no activeCamera and no entries in activeCameras — e.g. before any camera was created, or after the only camera was disposed/detached from the scene.

Common situations: Boilerplate that creates scene+meshes but omits camera creation; disposing a camera on cleanup while the render loop keeps running; multi-camera code that clears activeCameras and never restores activeCamera; copy-pasted scene code missing the camera line.

Related errors


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