{"record":{"id":"811c986fe30f08b4","repo":"BabylonJS/Babylon.js","slug":"flowgraphsetvariableblock-variable-and-variables","errorCode":null,"errorMessage":"FlowGraphSetVariableBlock: variable and variables are both defined","messagePattern":"FlowGraphSetVariableBlock: variable and variables are both defined","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/dev/core/src/FlowGraph/Blocks/Execution/flowGraphSetVariableBlock.pure.ts","lineNumber":34,"sourceCode":"     * The name of the variable to set.\n     */\n    variable?: string;\n\n    /**\n     * The name of the variables to set.\n     */\n    variables?: string[];\n}\n\n/**\n * This block will set a variable on the context.\n */\nexport class FlowGraphSetVariableBlock<T> extends FlowGraphExecutionBlockWithOutSignal {\n    constructor(config: IFlowGraphSetVariableBlockConfiguration) {\n        super(config);\n        // check if the variable is an array\n        if (config.variables && config.variable) {\n            throw new Error(\"FlowGraphSetVariableBlock: variable and variables are both defined\");\n        }\n        // check if we have either a variable or variables. If we have variables, set the inputs correctly\n        if (config.variables) {\n            for (const variable of config.variables) {\n                this.registerDataInput(variable, RichTypeAny);\n            }\n        } else {\n            this.registerDataInput(\"value\", RichTypeAny);\n        }\n    }\n\n    public override _execute(context: FlowGraphContext, _callingSignal: FlowGraphSignalConnection): void {\n        if (this.config?.variables) {\n            for (const variable of this.config.variables) {\n                this._saveVariable(context, variable);\n            }\n        } else {\n            this._saveVariable(context, this.config?.variable, \"value\");","sourceCodeStart":16,"sourceCodeEnd":52,"githubUrl":"https://github.com/BabylonJS/Babylon.js/blob/0592b347b8a4ee0236089ea86a749cacfdb266d8/packages/dev/core/src/FlowGraph/Blocks/Execution/flowGraphSetVariableBlock.pure.ts#L16-L52","documentation":"FlowGraphSetVariableBlock supports setting a single variable (config.variable) or multiple variables (config.variables) but not both. The constructor validates this and throws if both are provided, because the input wiring would be ambiguous.","triggerScenarios":"Constructing FlowGraphSetVariableBlock with a config containing both `variable: 'x'` and a non-empty `variables: [...]` array.","commonSituations":"Merging configs from two graph serializations; a saved config that accumulated both fields after an editor upgrade; copy-paste mistakes when switching a block from single to multi-variable mode.","solutions":["Remove `variable` from the config when using `variables` (or vice versa)","If migrating to multi-variable, move the single name into the variables array and delete the scalar field","Sanitize serialized configs on load to drop the redundant field"],"exampleFix":"// before\nnew FlowGraphSetVariableBlock({ variable: 'a', variables: ['a', 'b'] });\n// after\nnew FlowGraphSetVariableBlock({ variables: ['a', 'b'] });","handlingStrategy":"validation","validationCode":"if (config.variable && Array.isArray(config.variables) && config.variables.length) {\n  throw new Error('Provide either variable or variables, not both');\n}","typeGuard":"const isValidSetVariableConfig = <T>(c: IFlowGraphSetVariableBlockConfiguration<T>): boolean =>\n  !!(c.variables ? !c.variable : c.variable);","tryCatchPattern":"try { block = new FlowGraphSetVariableBlock(cfg); } catch (e) { if (e.message.includes('both defined')) { delete cfg.variable; block = new FlowGraphSetVariableBlock(cfg); } else throw e; }","preventionTips":["Sanitize persisted configs to enforce mutual exclusivity of variable/variables","When migrating single->multi, move the scalar into the array and delete it","Add a schema validator for block configs on graph load"],"tags":["flow-graph","configuration","validation"],"backgroundTag":"invalid-configuration","analyzedSha":"0592b347b8a4ee0236089ea86a749cacfdb266d8","analyzedAt":"2026-08-30T15:11:20.442Z","schemaVersion":2},"datasetVersion":"2026-08-30T18:17:15.746Z"}