BabylonJS/Babylon.js · error · Error
Variable index is not defined for variable interpolation blo
Error message
Variable index is not defined for variable interpolation block
What it means
The variable-interpolation block extraProcessor reads gltfBlock.configuration.variable.value[0] to find which static variable the block interpolates. It logs and throws when that index is missing or not a number, because the subsequent lookup parser.arrays.staticVariables[propertyIndex] would otherwise fail or misbehave.
Source
Thrown at packages/dev/loaders/src/glTF/2.0/Extensions/KHR_interactivity/declarationMapper.ts:1382
inputBlockIndex: 0,
outputBlockIndex: 3,
isVariable: true,
},
{
input: "value_0",
output: "value",
inputBlockIndex: 0,
outputBlockIndex: 4,
isVariable: true,
},
],
extraProcessor(gltfBlock, _declaration, _mapping, parser, serializedObjects) {
// is useSlerp is used, animationType should be set to be quaternion!
const serializedValueInterpolation = serializedObjects[0];
const propertyIndex = gltfBlock.configuration?.variable.value?.[0];
if (typeof propertyIndex !== "number") {
Logger.Error("Variable index is not defined for variable interpolation block");
throw new Error("Variable index is not defined for variable interpolation block");
}
const variable = parser.arrays.staticVariables[propertyIndex];
// if not set by useSlerp
if (typeof serializedValueInterpolation.config?.animationType?.value === "undefined") {
serializedValueInterpolation.config ||= {};
serializedValueInterpolation.config.animationType ||= {};
serializedValueInterpolation.config.animationType.value = getAnimationTypeByFlowGraphType(variable.type);
}
// variable/get configuration
const serializedGetVariable = serializedObjects[4];
serializedGetVariable.config ||= {};
serializedGetVariable.config.variable ||= {};
serializedGetVariable.config.variable.value = parser.getVariableName(propertyIndex);
return serializedObjects;
},
},View on GitHub (pinned to 0592b347b8)
Solutions
- Set configuration.variable to { "value": [numericVariableIndex] } matching an entry in staticVariables
- Re-export with a current KHR_interactivity exporter
- Validate the interactivity JSON against the schema before loading
Example fix
// before
"configuration": { "variable": { "value": ["score"] } }
// after
"configuration": { "variable": { "value": [4] } } Defensive patterns
Strategy: type-guard
Validate before calling
function hasVariableIndex(block) {
return typeof block.configuration?.variable?.value?.[0] === "number";
}
// check variable interpolation blocks before parsing Type guard
const hasVariableIndex = (b: { configuration?: { variable?: { value?: unknown[] } } }): b is { configuration: { variable: { value: [number] } } } => typeof b.configuration?.variable?.value?.[0] === "number"; Try / catch
try {
await loader.loadAsync(url);
} catch (e) {
if (e instanceof Error && e.message.includes("Variable index is not defined")) {
console.error("Variable interpolation block needs configuration.variable.value = [numericIndex].");
} else throw e;
} Prevention
- Reference static variables by numeric index, not name
- Validate configuration.variable on interpolation blocks in CI
- Keep exporter and loader schema versions in sync
When it happens
Trigger: An interactivity variable interpolation block without a "variable" configuration, with an empty value array, or with a non-numeric value (e.g. a variable name string instead of its index).
Common situations: Exporter writing variable names instead of indices; hand-edited configuration; assets from an older interactivity draft with a different configuration layout.
Related errors
- Event id should be a number
- Receive event should have a single configuration object, the
- Rotation quaternion input not found
- Switch should have a single configuration object, the cases
- MultiGate should have a single configuration object, the num
AI-assisted analysis of BabylonJS/Babylon.js@0592b347b8 (2026-08-30).
Data as JSON: /api/errors/2f601b5ed00bf858.
Report an issue: GitHub.