BabylonJS/Babylon.js · error · Error

Cannot transform value ${a}

Error message

Cannot transform value ${a}

What it means

FlowGraphVectorMathBlocks' TransformVector applies a matrix to a vector but only supports 2D, 3D, and 4D Vector2/Vector3/Vector4 inputs. When the input `a` is none of those recognized types (or the matrix operand combination falls through the switch's default), it throws this message. It is a polymorphic-dispatch guard: the block cannot figure out how to multiply the given value by the given matrix.

Source

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

    switch (className) {
        case FlowGraphTypes.Vector2:
            return (b as FlowGraphMatrix2D).transformVector(a as Vector2);
        case FlowGraphTypes.Vector3:
            return (b as FlowGraphMatrix3D).transformVector(a as Vector3);
        case FlowGraphTypes.Vector4:
            a = a as Vector4;
            // transform the vector 4 with the matrix here. Vector4.TransformCoordinates transforms a 3D coordinate, not Vector4.
            // Babylon's Matrix stores its elements column-major (m[0..3] is the first column), and the incoming
            // float4x4 values are column-major as well, so M * a reads down the columns: value[i] = sum_j M[i][j] * a[j]
            // with M[i][j] = m[j * 4 + i].
            return new Vector4(
                a.x * b.m[0] + a.y * b.m[4] + a.z * b.m[8] + a.w * b.m[12],
                a.x * b.m[1] + a.y * b.m[5] + a.z * b.m[9] + a.w * b.m[13],
                a.x * b.m[2] + a.y * b.m[6] + a.z * b.m[10] + a.w * b.m[14],
                a.x * b.m[3] + a.y * b.m[7] + a.z * b.m[11] + a.w * b.m[15]
            );
        default:
            throw new Error(`Cannot transform value ${a}`);
    }
}

/**
 * Configuration for the transform block.
 */
export interface IFlowGraphTransformBlockConfiguration extends IFlowGraphBlockConfiguration {
    /**
     * The vector type
     */
    vectorType: FlowGraphTypes;
}

/**
 * Transform a vector3 by a matrix.
 */
export class FlowGraphTransformBlock extends FlowGraphBinaryOperationBlock<FlowGraphVector, FlowGraphMatrix, FlowGraphVector> {
    constructor(config?: IFlowGraphTransformBlockConfiguration) {

View on GitHub (pinned to 0592b347b8)

Solutions

  1. Ensure the input to the transform block is a BABYLON.Vector2, Vector3, or Vector4 matching the matrix dimensions
  2. Insert a conversion block (e.g. Vector3 -> Vector4) or a correct-typed upstream block before the transform block
  3. Add a type check on the incoming data input at graph-build time and fail fast with a clearer message

Example fix

// before
const result = TransformVector(myQuaternion, myMatrix); // throws
// after
const vec = new Vector4(q.x, q.y, q.z, q.w);
const result = TransformVector(vec, myMatrix);
Defensive patterns

Strategy: validation

Validate before calling

function isTransformable(v) { return v instanceof BABYLON.Vector2 || v instanceof BABYLON.Vector3 || v instanceof BABYLON.Vector4; }
if (!isTransformable(input)) throw new TypeError('TransformVector requires Vector2/3/4, got ' + input);

Type guard

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

Try / catch

try { result = TransformVector(a, m); } catch (e) { if (e.message.startsWith('Cannot transform value')) { /* substitute identity/fallback */ } else throw e; }

Prevention

When it happens

Trigger: Calling the transform vector-math block with `a` being a scalar, quaternion, Matrix, null/undefined, or any non-Vector2/3/4 value, so the switch in TransformVector reaches its `default` branch.

Common situations: Wiring a wrong-typed data output (e.g. a quaternion or scalar from another block) into the transform block's input; JSON-authored graphs where a variable lost its type; refactors that changed the vector type of an upstream block.

Related errors


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