BabylonJS/Babylon.js · error · Error

Cannot slerp value ${a}

Error message

Cannot slerp value ${a}

What it means

_polymorphicSlerp dispatches spherical-linear interpolation based on the runtime class name of `a`, supporting only FlowGraphTypes.Vector2 and Vector3. Any other value (scalar, Vector4, quaternion, undefined) hits the default branch and throws. It exists so one slerp block can serve multiple vector types.

Source

Thrown at packages/dev/core/src/FlowGraph/Blocks/Data/Math/flowGraphVectorMathBlocks.pure.ts:386

/**
 * Spherical linear interpolation between two vectors.
 * Supports float2 and float3 vectors; the interpolation coefficient is a number.
 */
export class FlowGraphVectorSlerpBlock extends FlowGraphTernaryOperationBlock<FlowGraphVector, FlowGraphVector, number, FlowGraphVector> {
    constructor(config?: IFlowGraphBlockConfiguration) {
        super(RichTypeAny, RichTypeAny, RichTypeNumber, RichTypeAny, (a, b, c) => this._polymorphicSlerp(a, b, c), FlowGraphBlockNames.VectorSlerp, config);
    }

    private _polymorphicSlerp(a: FlowGraphVector, b: FlowGraphVector, c: number): FlowGraphVector {
        const className = _GetClassNameOf(a);
        switch (className) {
            case FlowGraphTypes.Vector2:
                return GetVector2Slerp(a as Vector2, b as Vector2, c);
            case FlowGraphTypes.Vector3:
                return GetVector3Slerp(a as Vector3, b as Vector3, c);
            default:
                throw new Error(`Cannot slerp value ${a}`);
        }
    }
}

/**
 * The configuration of the FlowGraphQuaternionFromAnglesBlock.
 */
export interface IFlowGraphQuaternionFromAnglesBlockConfiguration extends IFlowGraphBlockConfiguration {
    /**
     * The intrinsic Tait–Bryan rotation order, one of `xyz`, `xzy`, `yxz`, `yzx`, `zxy`, `zyx`.
     * Any other (or missing) value falls back to the spec default `yxz`.
     */
    order?: string;
}

/**
 * Creates a rotation quaternion from three Tait–Bryan intrinsic Euler angles applied in a
 * configurable order.

View on GitHub (pinned to 0592b347b8)

Solutions

  1. Use Vector2 or Vector3 inputs for the slerp block; convert other types first
  2. Ensure the input data inputs are connected and typed before execution
  3. For quaternions use Quaternion.Slerp (via the quaternion math blocks) instead

Example fix

// before
const r = slerpBlock.execute(vector4A, vector4B, t); // throws
// after
const r = Vector3.Lerp(new Vector3(a.x, a.y, a.z), new Vector3(b.x, b.y, b.z), t);
Defensive patterns

Strategy: type-guard

Validate before calling

if (!(a instanceof BABYLON.Vector2 || a instanceof BABYLON.Vector3)) throw new TypeError('slerp requires Vector2 or Vector3');

Type guard

const isSlerpable = (v: unknown): v is BABYLON.Vector2 | BABYLON.Vector3 =>
  v instanceof BABYLON.Vector2 || v instanceof BABYLON.Vector3;

Try / catch

try { return _polymorphicSlerp(a, b, t); } catch (e) { if (e.message.startsWith('Cannot slerp value')) { return Vector3.Lerp(toVec3(a), toVec3(b), t); } throw e; }

Prevention

When it happens

Trigger: Passing a value whose className is neither Vector2 nor Vector3 to the slerp vector-math block — e.g. a Vector4, a raw number, or an uninitialized data input.

Common situations: Connecting a Vector4 output into a slerp block; leaving the input data input unconnected so it resolves to undefined; hand-editing serialized graph JSON and changing a type.

Related errors


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