BabylonJS/Babylon.js · error
No active scene.
Error message
No active scene.
What it means
The `start-perf-instrumentation` CLI command requires an active scene from the inspector's scene context. When no scene has been loaded/opened (sceneContext.currentScene is null), there is nothing to instrument, so the command throws this error instead of silently starting no-op instrumentation.
Source
Thrown at packages/dev/inspector-v2/src/services/cli/statsCommandService.ts:34
consumes: [BridgeCommandRegistryIdentity, SceneContextIdentity],
factory: (commandRegistry, sceneContext) => {
let sceneInstrumentation: SceneInstrumentation | undefined;
let engineInstrumentation: EngineInstrumentation | undefined;
function disposeInstrumentation() {
sceneInstrumentation?.dispose();
sceneInstrumentation = undefined;
engineInstrumentation?.dispose();
engineInstrumentation = undefined;
}
const startPerfReg = commandRegistry.addCommand({
id: "start-perf-instrumentation",
description: "Start scene and engine performance instrumentation for frame stats collection.",
executeAsync: async () => {
const scene = sceneContext.currentScene;
if (!scene) {
throw new Error("No active scene.");
}
// Dispose any stale instrumentation (e.g. scene changed).
if (sceneInstrumentation && sceneInstrumentation.scene !== scene) {
disposeInstrumentation();
}
if (sceneInstrumentation) {
return "Performance instrumentation is already running.";
}
sceneInstrumentation = new SceneInstrumentation(scene);
sceneInstrumentation.captureActiveMeshesEvaluationTime = true;
sceneInstrumentation.captureRenderTargetsRenderTime = true;
sceneInstrumentation.captureFrameTime = true;
sceneInstrumentation.captureRenderTime = true;
sceneInstrumentation.captureInterFrameTime = true;
sceneInstrumentation.captureParticlesRenderTime = true;
View on GitHub (pinned to 0592b347b8)
Solutions
- Load or create a scene first, then run start-perf-instrumentation
- Wait for scene initialization (sceneContext.currentScene to be non-null / scene.whenReadyAsync()) before invoking the command
- If a scene was disposed, re-create or re-select it in the inspector before instrumenting
- Add a guard in automation scripts that polls for an active scene before issuing CLI commands
Example fix
// before
await cli.run("start-perf-instrumentation", {});
// after
if (!sceneContext.currentScene) {
await waitForScene(sceneContext);
}
await cli.run("start-perf-instrumentation", {}); Defensive patterns
Strategy: validation
Validate before calling
if (!sceneContext.currentScene) {
throw new Error("Cannot start instrumentation: no active scene. Load a scene first.");
}
await cli.run("start-perf-instrumentation", {}); Type guard
function hasActiveScene(ctx: { currentScene: BABYLON.Scene | null }): ctx is { currentScene: BABYLON.Scene } {
return ctx.currentScene !== null && !ctx.currentScene.isDisposed;
} Try / catch
try {
await cli.run("start-perf-instrumentation", {});
} catch (err) {
if (String(err).includes("No active scene")) {
await loadOrAwaitScene();
await cli.run("start-perf-instrumentation", {});
} else {
throw err;
}
} Prevention
- Always load/create a scene before issuing any scene-dependent CLI commands
- Await scene initialization promises in automation before calling CLI tools
- Re-check the scene context after engine disposal or scene switches
- Centralize a "wait for scene" helper in scripts instead of assuming a scene exists
When it happens
Trigger: Running start-perf-instrumentation before any scene is created or attached in the inspector; after the engine/scene was disposed; in a headless session where scene initialization hasn't completed yet.
Common situations: Calling the CLI command during tool startup before the playground/app loads a scene; scene disposal racing with instrumentation commands; automating the inspector without first awaiting scene initialization.
Related errors
- No active scene.
- No active scene.
- No active scene.
- Cannot upload to a 2D array texture that is not attached to
- No camera available for screenshot.
AI-assisted analysis of BabylonJS/Babylon.js@0592b347b8 (2026-08-30).
Data as JSON: /api/errors/38b8353f9a2e89ee.
Report an issue: GitHub.