{"record":{"id":"2f601b5ed00bf858","repo":"BabylonJS/Babylon.js","slug":"variable-index-is-not-defined-for-variable-interpo","errorCode":null,"errorMessage":"Variable index is not defined for variable interpolation block","messagePattern":"Variable index is not defined for variable interpolation block","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/dev/loaders/src/glTF/2.0/Extensions/KHR_interactivity/declarationMapper.ts","lineNumber":1382,"sourceCode":"                inputBlockIndex: 0,\n                outputBlockIndex: 3,\n                isVariable: true,\n            },\n            {\n                input: \"value_0\",\n                output: \"value\",\n                inputBlockIndex: 0,\n                outputBlockIndex: 4,\n                isVariable: true,\n            },\n        ],\n        extraProcessor(gltfBlock, _declaration, _mapping, parser, serializedObjects) {\n            // is useSlerp is used, animationType should be set to be quaternion!\n            const serializedValueInterpolation = serializedObjects[0];\n            const propertyIndex = gltfBlock.configuration?.variable.value?.[0];\n            if (typeof propertyIndex !== \"number\") {\n                Logger.Error(\"Variable index is not defined for variable interpolation block\");\n                throw new Error(\"Variable index is not defined for variable interpolation block\");\n            }\n            const variable = parser.arrays.staticVariables[propertyIndex];\n            // if not set by useSlerp\n            if (typeof serializedValueInterpolation.config?.animationType?.value === \"undefined\") {\n                serializedValueInterpolation.config ||= {};\n                serializedValueInterpolation.config.animationType ||= {};\n                serializedValueInterpolation.config.animationType.value = getAnimationTypeByFlowGraphType(variable.type);\n            }\n\n            // variable/get configuration\n            const serializedGetVariable = serializedObjects[4];\n            serializedGetVariable.config ||= {};\n            serializedGetVariable.config.variable ||= {};\n            serializedGetVariable.config.variable.value = parser.getVariableName(propertyIndex);\n\n            return serializedObjects;\n        },\n    },","sourceCodeStart":1364,"sourceCodeEnd":1400,"githubUrl":"https://github.com/BabylonJS/Babylon.js/blob/0592b347b8a4ee0236089ea86a749cacfdb266d8/packages/dev/loaders/src/glTF/2.0/Extensions/KHR_interactivity/declarationMapper.ts#L1364-L1400","documentation":"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.","triggerScenarios":"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).","commonSituations":"Exporter writing variable names instead of indices; hand-edited configuration; assets from an older interactivity draft with a different configuration layout.","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"],"exampleFix":"// before\n\"configuration\": { \"variable\": { \"value\": [\"score\"] } }\n// after\n\"configuration\": { \"variable\": { \"value\": [4] } }","handlingStrategy":"type-guard","validationCode":"function hasVariableIndex(block) {\n  return typeof block.configuration?.variable?.value?.[0] === \"number\";\n}\n// check variable interpolation blocks before parsing","typeGuard":"const hasVariableIndex = (b: { configuration?: { variable?: { value?: unknown[] } } }): b is { configuration: { variable: { value: [number] } } } => typeof b.configuration?.variable?.value?.[0] === \"number\";","tryCatchPattern":"try {\n  await loader.loadAsync(url);\n} catch (e) {\n  if (e instanceof Error && e.message.includes(\"Variable index is not defined\")) {\n    console.error(\"Variable interpolation block needs configuration.variable.value = [numericIndex].\");\n  } else throw e;\n}","preventionTips":["Reference static variables by numeric index, not name","Validate configuration.variable on interpolation blocks in CI","Keep exporter and loader schema versions in sync"],"tags":["gltf","interactivity","flow-graph","type-error"],"backgroundTag":"gltf-interactivity-invalid-configuration","analyzedSha":"0592b347b8a4ee0236089ea86a749cacfdb266d8","analyzedAt":"2026-08-30T15:11:20.442Z","schemaVersion":2},"datasetVersion":"2026-08-30T18:17:15.746Z"}