BabylonJS/Babylon.js · error
cameraUniqueId must be a number.
Error message
cameraUniqueId must be a number.
What it means
Thrown by the 'screenshot' command when args.cameraUniqueId is provided but cannot be parsed by parseInt(…, 10). Only fully numeric strings are accepted; anything else (letters, empty string, hex notation) yields NaN and triggers this error.
Source
Thrown at packages/dev/inspector-v2/src/services/cli/screenshotCommandService.ts:53
name: "precision",
description: "Resolution multiplier (e.g. 2 for double resolution). Defaults to 1.",
required: false,
},
],
executeAsync: async (args) => {
const scene = sceneContext.currentScene;
if (!scene) {
throw new Error("No active scene.");
}
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.");
}
View on GitHub (pinned to 0592b347b8)
Solutions
- Pass the camera's numeric uniqueId as a decimal string (find it via a scene query command).
- Omit cameraUniqueId entirely to let the command auto-resolve the active/frame-graph camera.
- Trim/normalize the value before passing it; leading/trailing spaces are tolerated by parseInt but other characters are not.
Example fix
// before
await execute("screenshot", { cameraUniqueId: "mainCamera" });
// after
await execute("screenshot", { cameraUniqueId: "7" }); Defensive patterns
Strategy: validation
Validate before calling
if (args.cameraUniqueId != null && Number.isNaN(Number.parseInt(args.cameraUniqueId, 10))) throw new TypeError(`cameraUniqueId must be a decimal number, got: ${JSON.stringify(args.cameraUniqueId)}`); Type guard
function isNumericId(v: unknown): v is string { return typeof v === "string" && /^-?\d+$/.test(v.trim()); } Try / catch
try {
await screenshot({ cameraUniqueId: camId });
} catch (e) {
if (e instanceof Error && e.message === "cameraUniqueId must be a number.") {
return screenshot({}); // fall back to active camera
}
throw e;
} Prevention
- Use numeric uniqueIds, not camera names/labels.
- Resolve ids via a scene query command before passing them.
- Omit cameraUniqueId when the active camera is acceptable.
When it happens
Trigger: Calling screenshot with cameraUniqueId="cam1", "", "0x10", or any non-decimal value while the argument is truthy.
Common situations: Passing a camera name instead of its uniqueId; copying an object reference or label from the scene explorer; a script interpolating an undefined variable into the string.
Related errors
- uniqueId must be a number.
- No camera found with uniqueId ${cameraId}.
- No camera available for screenshot.
- precision must be a finite number greater than 0.
- width must be a finite positive integer.
AI-assisted analysis of BabylonJS/Babylon.js@0592b347b8 (2026-08-30).
Data as JSON: /api/errors/e52db798a5bc4282.
Report an issue: GitHub.