BabylonJS/Babylon.js · error · Error

Cannot get dot product of ${a} and ${b}

Error message

Cannot get dot product of ${a} and ${b}

What it means

The Dot Product block's _polymorphicDot computes .dot() only for Vector2, Vector3, Vector4 and Quaternion operand types; any other operand kind (scalar, boolean, Matrix, undefined) reaches the default case and throws 'Cannot get dot product of ...'. Both operands must be vector-like values of compatible dimensions.

Source

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

/**
 * Dot product block.
 */
export class FlowGraphDotBlock extends FlowGraphBinaryOperationBlock<FlowGraphVector, FlowGraphVector, number> {
    constructor(config?: IFlowGraphBlockConfiguration) {
        super(RichTypeAny, RichTypeAny, RichTypeNumber, (a, b) => this._polymorphicDot(a, b), FlowGraphBlockNames.Dot, config);
    }

    private _polymorphicDot(a: FlowGraphVector, b: FlowGraphVector) {
        const className = _GetClassNameOf(a);
        switch (className) {
            case FlowGraphTypes.Vector2:
            case FlowGraphTypes.Vector3:
            case FlowGraphTypes.Vector4:
            case FlowGraphTypes.Quaternion:
                // casting is needed because dot requires both to be the same type
                return (a as Vector3).dot(b as Vector3);
            default:
                throw new Error(`Cannot get dot product of ${a} and ${b}`);
        }
    }
}

/**
 * Cross product block.
 */
export class FlowGraphCrossBlock extends FlowGraphBinaryOperationBlock<Vector3, Vector3, Vector3> {
    constructor(config?: IFlowGraphBlockConfiguration) {
        super(RichTypeVector3, RichTypeVector3, RichTypeVector3, (a, b) => Vector3.Cross(a, b), FlowGraphBlockNames.Cross, config);
    }
}

/**
 * 2D rotation block.
 */
export class FlowGraphRotate2DBlock extends FlowGraphBinaryOperationBlock<Vector2, number, Vector2> {
    constructor(config?: IFlowGraphBlockConfiguration) {

View on GitHub (pinned to 0592b347b8)

Solutions

  1. Connect vector-typed values (Vector2/3/4 or Quaternion) to both inputs; promote scalars by constructing a vector first (e.g. new Vector3(s, s, s) block).
  2. Match dimensions: convert Vector2 to Vector3 (append z) before dotting with a Vector3.
  3. Fix the upstream wiring so both ports receive vector outputs.

Example fix

// before: scalar into Dot block -> throws
dotBlock.a.connect(scalarOutput); // number

// after: vectors on both inputs
dotBlock.a.connect(dirABlock.output); // Vector3
dotBlock.b.connect(dirBBlock.output); // Vector3
Defensive patterns

Strategy: type-guard

Validate before calling

// before Dot block runs
function validDotInputs(a, b) {
  const ok = (v) => v instanceof BABYLON.Vector2 || v instanceof BABYLON.Vector3 ||
                    v instanceof BABYLON.Vector4 || v instanceof BABYLON.Quaternion;
  return ok(a) && ok(b);
}
if (!validDotInputs(dotInputA, dotInputB)) throw new TypeError('Dot inputs must both be vector-like');

Type guard

function isVectorLike(v): v is BABYLON.Vector2 | BABYLON.Vector3 | BABYLON.Vector4 | BABYLON.Quaternion {
  return v != null && typeof (v as any).dot === 'function';
}

Try / catch

try {
  result = dotBlock.evaluate(context);
} catch (e) {
  if (e.message.startsWith('Cannot get dot product of')) {
    // promote scalars into matching vectors and retry
    const va = vecFromScalar(a), vb = vecFromScalar(b);
    result = va.dot(vb);
  } else { throw e; }
}

Prevention

When it happens

Trigger: Executing FlowGraphDotBlock with a scalar (number/FlowGraphInteger), boolean, or Matrix on either input port; also feeding two vectors of differing dimension where the engine's dot() cannot reconcile them (cast as Vector3 internally).

Common situations: Wiring a numeric output (e.g. from a previous dot or length computation) back into a Dot block instead of a vector; mixing Vector2 and Vector3 inputs expecting automatic promotion; a graph where one vector input defaulted to a scalar after deserialization.

Related errors


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