BabylonJS/Babylon.js · error
Invalid scene provided to GetInspectorGizmoManager
Error message
Invalid scene provided to GetInspectorGizmoManager
What it means
GetInspectorGizmoManager looks up (or, with create=true, creates) the inspector's GizmoManager stored on scene.reservedDataStore. It throws when create=true is requested but the passed scene is null/undefined, since a gizmo manager cannot be created without a scene.
Source
Thrown at packages/dev/inspector/src/inspectorGizmoManager.ts:22
import { GizmoManager } from "core/Gizmos/gizmoManager";
import { FrameGraphUtils } from "core/FrameGraph/frameGraphUtils";
function CreateInspectorGizmoManager(scene: Scene): GizmoManager {
const layer1 = scene.frameGraph ? FrameGraphUtils.CreateUtilityLayerRenderer(scene.frameGraph) : new UtilityLayerRenderer(scene);
const layer2 = scene.frameGraph ? FrameGraphUtils.CreateUtilityLayerRenderer(scene.frameGraph) : new UtilityLayerRenderer(scene);
const gizmoManager = new GizmoManager(scene, undefined, layer1, layer2);
scene.reservedDataStore ??= {};
scene.reservedDataStore.gizmoManager = gizmoManager;
return gizmoManager;
}
export function GetInspectorGizmoManager(scene: Nullable<Scene> | undefined, create: true): GizmoManager;
export function GetInspectorGizmoManager(scene: Nullable<Scene> | undefined, create: false): Nullable<GizmoManager>;
export function GetInspectorGizmoManager(scene: Nullable<Scene> | undefined, create: boolean): Nullable<GizmoManager> {
let gizmoManager = scene && scene.reservedDataStore && scene.reservedDataStore.gizmoManager ? (scene.reservedDataStore.gizmoManager as GizmoManager) : null;
if (!gizmoManager && create) {
if (!scene) {
throw new Error("Invalid scene provided to GetInspectorGizmoManager");
}
gizmoManager = CreateInspectorGizmoManager(scene);
}
return gizmoManager;
}
export function DisposeInspectorGizmoManager(scene: Nullable<Scene> | undefined): void {
const gizmoManager = GetInspectorGizmoManager(scene, false);
if (!gizmoManager) {
return;
}
gizmoManager.dispose();
scene!.reservedDataStore.gizmoManager = null;
}
View on GitHub (pinned to 0592b347b8)
Solutions
- Ensure a valid Scene instance is created and passed to the inspector before calling gizmo-related APIs.
- Guard calls with a scene null-check before invoking gizmoManager/toggleGizmo.
- If the scene was disposed, reinitialize the inspector with the new scene instead of reusing stale references.
- Pass create=false first (via the overload) to probe existence without triggering the throw.
Example fix
// before const manager = GetInspectorGizmoManager(maybeScene, true); // throws if null // after if (!maybeScene) return null; const manager = GetInspectorGizmoManager(maybeScene, true);
Defensive patterns
Strategy: type-guard
Validate before calling
function canGetGizmoManager(scene: unknown): boolean {
return !!scene && typeof (scene as Scene).getEngine === "function";
} Type guard
function isScene(s: unknown): s is Scene {
return !!s && typeof (s as Scene).getEngine === "function" && typeof (s as Scene).reservedDataStore !== "undefined";
} Try / catch
try {
const mgr = GetInspectorGizmoManager(scene, true);
} catch (e) {
if (e instanceof Error && e.message === "Invalid scene provided to GetInspectorGizmoManager") {
console.warn("Inspector not attached to a scene; gizmos unavailable.");
} else throw e;
} Prevention
- Only call inspector gizmo APIs after the inspector is bound to a live scene
- Clear/refresh inspector references on scene disposal
- Use the create=false overload to probe existence safely
- Null-check scene at every call site that forwards it to the inspector
When it happens
Trigger: Calling gizmoManager/toggleGizmo/manager accessors (which call GetInspectorGizmoManager(scene, true)) before the inspector is attached to a scene, or after the scene reference was cleared to null, while asking to create the manager.
Common situations: Toggling gizmos in the inspector UI before scene selection completes; holding a stale inspector reference after scene disposal; calling inspector helpers from code that never received the scene (e.g. during early init).
Related errors
- No active scene.
- No scene available to import mesh to
- No engine available
- No scene available to append to
- Cannot upload to a 2D array texture that is not attached to
AI-assisted analysis of BabylonJS/Babylon.js@0592b347b8 (2026-08-30).
Data as JSON: /api/errors/b713486b40e1d45a.
Report an issue: GitHub.