BabylonJS/Babylon.js · error · Error

FlowGraphSetVariableBlock: variable and variables are both d

Error message

FlowGraphSetVariableBlock: variable and variables are both defined

What it means

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.

Source

Thrown at packages/dev/core/src/FlowGraph/Blocks/Execution/flowGraphSetVariableBlock.pure.ts:34

     * The name of the variable to set.
     */
    variable?: string;

    /**
     * The name of the variables to set.
     */
    variables?: string[];
}

/**
 * This block will set a variable on the context.
 */
export class FlowGraphSetVariableBlock<T> extends FlowGraphExecutionBlockWithOutSignal {
    constructor(config: IFlowGraphSetVariableBlockConfiguration) {
        super(config);
        // check if the variable is an array
        if (config.variables && config.variable) {
            throw new Error("FlowGraphSetVariableBlock: variable and variables are both defined");
        }
        // check if we have either a variable or variables. If we have variables, set the inputs correctly
        if (config.variables) {
            for (const variable of config.variables) {
                this.registerDataInput(variable, RichTypeAny);
            }
        } else {
            this.registerDataInput("value", RichTypeAny);
        }
    }

    public override _execute(context: FlowGraphContext, _callingSignal: FlowGraphSignalConnection): void {
        if (this.config?.variables) {
            for (const variable of this.config.variables) {
                this._saveVariable(context, variable);
            }
        } else {
            this._saveVariable(context, this.config?.variable, "value");

View on GitHub (pinned to 0592b347b8)

Solutions

  1. Remove `variable` from the config when using `variables` (or vice versa)
  2. If migrating to multi-variable, move the single name into the variables array and delete the scalar field
  3. Sanitize serialized configs on load to drop the redundant field

Example fix

// before
new FlowGraphSetVariableBlock({ variable: 'a', variables: ['a', 'b'] });
// after
new FlowGraphSetVariableBlock({ variables: ['a', 'b'] });
Defensive patterns

Strategy: validation

Validate before calling

if (config.variable && Array.isArray(config.variables) && config.variables.length) {
  throw new Error('Provide either variable or variables, not both');
}

Type guard

const isValidSetVariableConfig = <T>(c: IFlowGraphSetVariableBlockConfiguration<T>): boolean =>
  !!(c.variables ? !c.variable : c.variable);

Try / catch

try { block = new FlowGraphSetVariableBlock(cfg); } catch (e) { if (e.message.includes('both defined')) { delete cfg.variable; block = new FlowGraphSetVariableBlock(cfg); } else throw e; }

Prevention

When it happens

Trigger: Constructing FlowGraphSetVariableBlock with a config containing both `variable: 'x'` and a non-empty `variables: [...]` array.

Common situations: 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.

Related errors


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