BabylonJS/Babylon.js · error
No active scene.
Error message
No active scene.
What it means
Thrown by the 'start-perf-trace' inspector CLI command when sceneContext.currentScene is null/undefined. Performance tracing instruments a live Babylon scene, so there is nothing to trace without an active scene. This fails fast before the perf collector is started.
Source
Thrown at packages/dev/inspector-v2/src/services/cli/perfTraceCommandService.ts:25
import "core/Misc/PerformanceViewer/performanceViewerSceneExtension";
/**
* Service that registers CLI commands for performance tracing using the PerformanceViewerCollector.
* start-perf-trace begins collecting data, stop-perf-trace stops and returns the collected data as JSON.
*/
export const PerfTraceCommandServiceDefinition: ServiceDefinition<[], [IBridgeCommandRegistry, ISceneContext]> = {
friendlyName: "Perf Trace Command Service",
consumes: [BridgeCommandRegistryIdentity, SceneContextIdentity],
factory: (commandRegistry, sceneContext) => {
let perfCollector: PerformanceViewerCollector | undefined;
const startReg = commandRegistry.addCommand({
id: "start-perf-trace",
description: "Start collecting performance trace data.",
executeAsync: async () => {
const scene = sceneContext.currentScene;
if (!scene) {
throw new Error("No active scene.");
}
if (perfCollector?.isStarted) {
return "Performance trace is already running.";
}
perfCollector = scene.getPerfCollector();
perfCollector.stop();
perfCollector.clear(false);
perfCollector.addCollectionStrategies(...DefaultPerfStrategies);
perfCollector.start(true);
return "Performance trace started.";
},
});
const stopReg = commandRegistry.addCommand({
id: "stop-perf-trace",
View on GitHub (pinned to 0592b347b8)
Solutions
- Create/switch to a scene first (run the scene-creation command or wait for app initialization) and retry start-perf-trace.
- If scripting, gate the trace start on scene readiness: await the app's 'scene ready' event before invoking the command.
- Verify the inspector is attached to the same sceneContext the application actually uses (not a detached second instance).
Example fix
// before
await execute("start-perf-trace", {}); // scene not created yet
// after
await onSceneReady();
await execute("start-perf-trace", {}); Defensive patterns
Strategy: try-catch
Validate before calling
if (!sceneContext.currentScene) throw new Error("Cannot start perf trace: no active scene. Create a scene first."); Type guard
function hasActiveScene(ctx: { currentScene: unknown }): boolean { return ctx.currentScene != null; } Try / catch
try {
await startPerfTrace();
} catch (e) {
if (e instanceof Error && e.message === "No active scene.") {
await waitForSceneReady();
await startPerfTrace();
} else throw e;
} Prevention
- Sequence CLI/agent actions after scene-creation completes (await 'scene ready').
- Re-check currentScene after hot reloads; dispose can null it.
- Confirm the inspector is bound to the app's real sceneContext.
When it happens
Trigger: Executing 'start-perf-trace' before any scene has been created, or after the scene was disposed/cleared, or when the inspector is attached to a context whose sceneContext was never wired to a running engine.
Common situations: Running the inspector/CLI agent at startup before the engine creates the first scene; scene disposed during hot-reload; connecting the inspector to a headless bootstrap that never initializes a scene.
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/c5624e0e9a21c1ff.
Report an issue: GitHub.