{"record":{"id":"896f5f99f572dbef","repo":"BabylonJS/Babylon.js","slug":"plugin-version-is-incorrect-expected-version-2","errorCode":null,"errorMessage":"Plugin version is incorrect. Expected version 2.","messagePattern":"Plugin version is incorrect\\. Expected version 2\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"packages/dev/core/src/Physics/v2/physicsBody.ts","lineNumber":112,"sourceCode":"     *  - PhysicsMotionType.ANIMATED - They behave like dynamic bodies, but they won't be affected by other bodies, but still push other bodies out of the way.\r\n     * @param startsAsleep - Whether the physics body should start in a sleeping state (not a guarantee). Defaults to false.\r\n     * @param scene - The scene containing the physics engine.\r\n     *\r\n     * This code is useful for creating a physics body for a given Transform Node in a scene.\r\n     * It checks the version of the physics engine and the physics plugin, and initializes the body accordingly.\r\n     * It also sets the node's rotation quaternion if it is not already set. Finally, it adds the body to the physics engine.\r\n     */\r\n    constructor(transformNode: TransformNode, motionType: PhysicsMotionType, startsAsleep: boolean, scene: Scene) {\r\n        if (!scene) {\r\n            return;\r\n        }\r\n        const physicsEngine = scene.getPhysicsEngine() as PhysicsEngine;\r\n        if (!physicsEngine) {\r\n            throw new Error(\"No Physics Engine available.\");\r\n        }\r\n        this._physicsEngine = physicsEngine;\r\n        if (physicsEngine.getPluginVersion() != 2) {\r\n            throw new Error(\"Plugin version is incorrect. Expected version 2.\");\r\n        }\r\n        const physicsPlugin = physicsEngine.getPhysicsPlugin();\r\n        if (!physicsPlugin) {\r\n            throw new Error(\"No Physics Plugin available.\");\r\n        }\r\n\r\n        this._physicsPlugin = physicsPlugin;\r\n        if (!transformNode.rotationQuaternion) {\r\n            transformNode.rotationQuaternion = Quaternion.FromEulerAngles(transformNode.rotation.x, transformNode.rotation.y, transformNode.rotation.z);\r\n        }\r\n\r\n        this.startAsleep = startsAsleep;\r\n\r\n        // only dynamic and animated body needs sync from physics to transformNode\r\n        this.disableSync = motionType == PhysicsMotionType.STATIC;\r\n\r\n        // instances?\r\n        const m = transformNode as Mesh;\r","sourceCodeStart":94,"sourceCodeEnd":130,"githubUrl":"https://github.com/BabylonJS/Babylon.js/blob/0592b347b8a4ee0236089ea86a749cacfdb266d8/packages/dev/core/src/Physics/v2/physicsBody.ts#L94-L130","documentation":"PhysicsBody is the v2 physics API. After finding the scene's engine it checks physicsEngine.getPluginVersion() == 2; if the engine was created with a v1 plugin (e.g. legacy Cannon/Oimo plugins), the v2 body API is incompatible and the constructor throws to prevent undefined behavior.","triggerScenarios":"new PhysicsBody(...) when the scene engine was enabled with a v1 plugin such as CannonJSPlugin/OimoJSPlugin/AmmoJSPlugin, so getPluginVersion() returns 1 and the check at physicsBody.ts:112 fails.","commonSituations":"Upgrading code that used the old v1 API (PhysicsImpostor era plugins) but keeping the legacy plugin; enabling physics with a legacy plugin by mistake; documentation mixing v1 and v2 examples.","solutions":["Enable physics with a v2 plugin: const havok = await HavokPlugin(); scene.enablePhysics(grav, havok); then use PhysicsBody/PhysicsAggregate instead of PhysicsImpostor.","Verify the plugin's getPluginVersion() === 2 before constructing v2 physics objects.","If you must stay on a v1 plugin, use the v1 API (PhysicsImpostor) rather than PhysicsBody."],"exampleFix":"// before\nscene.enablePhysics(grav, new CannonJSPlugin());\nconst body = new PhysicsBody(mesh, PhysicsMotionType.DYNAMIC, false, scene);\n// after\nconst havok = await HavokPlugin();\nscene.enablePhysics(grav, havok); // version 2 plugin\nconst body = new PhysicsBody(mesh, PhysicsMotionType.DYNAMIC, false, scene);","handlingStrategy":"validation","validationCode":"const engine = scene.getPhysicsEngine() as PhysicsEngine | null;\nif (!engine || engine.getPluginVersion() !== 2) {\n  throw new Error(\"PhysicsBody requires a v2 physics plugin (e.g. HavokPlugin)\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always enable physics with a v2 plugin such as HavokPlugin when using PhysicsBody/PhysicsAggregate.","Use PhysicsImpostor only with legacy v1 plugins; never mix APIs.","Check engine.getPluginVersion() === 2 as a startup assertion."],"tags":["physics","plugin-version","api-mismatch","babylon"],"backgroundTag":"plugin-version-mismatch","analyzedSha":"0592b347b8a4ee0236089ea86a749cacfdb266d8","analyzedAt":"2026-08-30T15:11:20.442Z","schemaVersion":2},"datasetVersion":"2026-08-30T18:17:15.746Z"}