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

  1. Set configuration.variable to { "value": [numericVariableIndex] } matching an entry in staticVariables
  2. Re-export with a current KHR_interactivity exporter
  3. 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

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


AI-assisted analysis of BabylonJS/Babylon.js@0592b347b8 (2026-08-30). Data as JSON: /api/errors/2f601b5ed00bf858. Report an issue: GitHub.