{"record":{"id":"f48bc32100eb428f","repo":"BabylonJS/Babylon.js","slug":"no-physics-engine-available","errorCode":null,"errorMessage":"No Physics Engine available.","messagePattern":"No Physics Engine available\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"packages/dev/core/src/Physics/v2/physicsBody.ts","lineNumber":108,"sourceCode":"     * @param transformNode - The Transform Node to construct the physics body for. For better performance, it is advised that this node does not have a parent.\r\n     * @param motionType - The motion type of the physics body. The options are:\r\n     *  - PhysicsMotionType.STATIC - Static bodies are not moving and unaffected by forces or collisions. They are good for level boundaries or terrain.\r\n     *  - PhysicsMotionType.DYNAMIC - Dynamic bodies are fully simulated. They can move and collide with other objects.\r\n     *  - 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","sourceCodeStart":90,"sourceCodeEnd":126,"githubUrl":"https://github.com/BabylonJS/Babylon.js/blob/0592b347b8a4ee0236089ea86a749cacfdb266d8/packages/dev/core/src/Physics/v2/physicsBody.ts#L90-L126","documentation":"PhysicsBody's constructor pulls the physics engine from scene.getPhysicsEngine(). If the scene has no engine (enablePhysics was never called or returned false), the body cannot register with anything and the constructor throws immediately. It is a guard against silently creating a body that would never simulate.","triggerScenarios":"new PhysicsBody(mesh, PhysicsMotionType.DYNAMIC, false, scene) on a scene where scene.getPhysicsEngine() returns null — HavokPlugin not enabled, or the scene is not the one physics was enabled on.","commonSituations":"Forgetting await HavokPlugin() / scene.enablePhysics before creating bodies; enabling physics on a different Scene instance than the one used to build bodies; enablePhysics silently failing because the plugin failed to initialize.","solutions":["Initialize physics first: const havok = await HavokPlugin(); scene.enablePhysics(new Vector3(0,-9.81,0), havok); before creating any PhysicsBody.","Check scene.getPhysicsEngine() is truthy before constructing bodies; guard creation behind that check.","Confirm you enabled physics on the same Scene object the bodies are created in."],"exampleFix":"// before\nconst body = new PhysicsBody(box, PhysicsMotionType.DYNAMIC, false, scene);\n// after\nconst havok = await HavokPlugin();\nif (!scene.enablePhysics(new Vector3(0, -9.81, 0), havok)) throw new Error(\"physics failed to init\");\nconst body = new PhysicsBody(box, PhysicsMotionType.DYNAMIC, false, scene);","handlingStrategy":"validation","validationCode":"if (!scene.getPhysicsEngine()) {\n  throw new Error(\"enable physics before creating bodies: await HavokPlugin(); scene.enablePhysics(gravity, havok)\");\n}\nconst body = new PhysicsBody(mesh, PhysicsMotionType.DYNAMIC, false, scene);","typeGuard":"function hasPhysicsEngine(scene: Scene): scene is Scene & { getPhysicsEngine(): PhysicsEngine } {\n  return !!scene.getPhysicsEngine();\n}","tryCatchPattern":"try {\n  const body = new PhysicsBody(mesh, PhysicsMotionType.DYNAMIC, false, scene);\n} catch (e) {\n  if ((e as Error).message.includes(\"No Physics Engine available\")) {\n    const havok = await HavokPlugin();\n    scene.enablePhysics(new Vector3(0, -9.81, 0), havok);\n    // retry body creation here\n  } else { throw e; }\n}","preventionTips":["Initialize physics (await HavokPlugin + scene.enablePhysics) at app startup, before any body creation.","Use the exact Scene instance physics was enabled on for all bodies.","Assert scene.getPhysicsEngine() exists in your physics setup helper."],"tags":["physics","scene","initialization","babylon"],"backgroundTag":"physics-engine-not-enabled","analyzedSha":"0592b347b8a4ee0236089ea86a749cacfdb266d8","analyzedAt":"2026-08-30T15:11:20.442Z","schemaVersion":2},"datasetVersion":"2026-08-30T18:17:15.746Z"}