BabylonJS/Babylon.js · error

Unknown motion type: ${type}

Error message

Unknown motion type: ${type}

What it means

HavokPlugin translates Babylon PhysicsMotionType values to Havok MotionType constants via a switch. If the incoming value matches none of STATIC/ANIMATED/DYNAMIC cases, the mapping has no Havok equivalent and the plugin throws rather than guessing. This indicates the caller passed an invalid or unmapped motion type.

Source

Thrown at packages/dev/core/src/Physics/v2/Plugins/havokPlugin.ts:1278

    /**
     * Gets the motion type of a physics body.
     * @param body - The physics body to get the motion type from.
     * @param instanceIndex - The index of the instance to get the motion type from. If not specified, the motion type of the first instance will be returned.
     * @returns The motion type of the physics body.
     */
    public getMotionType(body: PhysicsBody, instanceIndex?: number): PhysicsMotionType {
        const pluginRef = this._getPluginReference(body, instanceIndex);
        const type = this._hknp.HP_Body_GetMotionType(pluginRef.hpBodyId)[1];
        switch (type) {
            case this._hknp.MotionType.STATIC:
                return PhysicsMotionType.STATIC;
            case this._hknp.MotionType.KINEMATIC:
                return PhysicsMotionType.ANIMATED;
            case this._hknp.MotionType.DYNAMIC:
                return PhysicsMotionType.DYNAMIC;
        }
        throw new Error("Unknown motion type: " + type);
    }

    /**
     * sets the activation control mode of a physics body, for instance if you need the body to never sleep.
     * @param body - The physics body to set the activation control mode.
     * @param controlMode - The activation control mode.
     */
    public setActivationControl(body: PhysicsBody, controlMode: PhysicsActivationControl): void {
        switch (controlMode) {
            case PhysicsActivationControl.ALWAYS_ACTIVE:
                this._hknp.HP_Body_SetActivationControl(body._pluginData.hpBodyId, this._hknp.ActivationControl.ALWAYS_ACTIVE);
                break;
            case PhysicsActivationControl.ALWAYS_INACTIVE:
                this._hknp.HP_Body_SetActivationControl(body._pluginData.hpBodyId, this._hknp.ActivationControl.ALWAYS_INACTIVE);
                break;
            case PhysicsActivationControl.SIMULATION_CONTROLLED:
                this._hknp.HP_Body_SetActivationControl(body._pluginData.hpBodyId, this._hknp.ActivationControl.SIMULATION_CONTROLLED);
                break;

View on GitHub (pinned to 0592b347b8)

Solutions

  1. Only pass values from the imported PhysicsMotionType enum (STATIC, ANIMATED, DYNAMIC); never raw numbers or strings.
  2. Verify @babylonjs/core and @babylonjs/havok are at compatible versions in package.json and reinstall so a single shared enum module is used.
  3. Log the value before creating the body to confirm it is one of the three valid enum members.

Example fix

// before
const body = new PhysicsBody(mesh, 4 as any, false, scene);
// after
const body = new PhysicsBody(mesh, PhysicsMotionType.DYNAMIC, false, scene);
Defensive patterns

Strategy: validation

Validate before calling

const VALID = [PhysicsMotionType.STATIC, PhysicsMotionType.ANIMATED, PhysicsMotionType.DYNAMIC];
if (!VALID.includes(motionType)) {
  throw new Error(`motionType must be a PhysicsMotionType enum member, got: ${motionType}`);
}

Type guard

function isValidMotionType(t: unknown): t is PhysicsMotionType {
  return t === PhysicsMotionType.STATIC || t === PhysicsMotionType.ANIMATED || t === PhysicsMotionType.DYNAMIC;
}

Prevention

When it happens

Trigger: Passing an invalid/undefined value (or a stale import of PhysicsMotionType from a mismatched Babylon build) to body construction or physicsBody.setMotionType(), so the internal conversion switch falls through to the throw at havokPlugin.ts:1278.

Common situations: Constructing a PhysicsBody with a hand-written numeric motion type; mixing @babylonjs/core and @babylonjs/havok versions so enum values differ; typos like PhysicsMotionType.KINEMATIC (the Babylon name is ANIMATED).

Related errors


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