{"record":{"id":"f64cdfec23b75719","repo":"BabylonJS/Babylon.js","slug":"no-physics-engine-available-f64cdf","errorCode":null,"errorMessage":"No Physics Engine available.","messagePattern":"No Physics Engine available\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/dev/core/src/Physics/v2/physicsShape.ts","lineNumber":72,"sourceCode":"     * Constructs a new physics shape.\r\n     * @param options The options for the physics shape. These are:\r\n     *  * type: The type of the shape. This can be one of the following: SPHERE, BOX, CAPSULE, CYLINDER, CONVEX_HULL, MESH, HEIGHTFIELD, CONTAINER\r\n     *  * parameters: The parameters of the shape.\r\n     *  * pluginData: The plugin data of the shape. This is used if you already have a reference to the object on the plugin side.\r\n     * You need to specify either type or pluginData.\r\n     * @param scene The scene the shape belongs to.\r\n     *\r\n     * This code is useful for creating a new physics shape with the given type, options, and scene.\r\n     * It also checks that the physics engine and plugin version are correct.\r\n     * If not, it throws an error. This ensures that the shape is created with the correct parameters and is compatible with the physics engine.\r\n     */\r\n    constructor(options: PhysicShapeOptions, scene: Scene) {\r\n        if (!scene) {\r\n            return;\r\n        }\r\n        const physicsEngine = scene.getPhysicsEngine();\r\n        if (!physicsEngine) {\r\n            throw new Error(\"No Physics Engine available.\");\r\n        }\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        this._physicsPlugin = physicsPlugin as IPhysicsEnginePluginV2;\r\n\r\n        if (options.pluginData !== undefined && options.pluginData !== null) {\r\n            this._pluginData = options.pluginData;\r\n            this._type = this._physicsPlugin.getShapeType(this);\r\n        } else if (options.type !== undefined && options.type !== null) {\r\n            this._type = options.type;\r\n            const parameters = options.parameters ?? {};\r\n            this._physicsPlugin.initShape(this, options.type, parameters);\r\n        }\r","sourceCodeStart":54,"sourceCodeEnd":90,"githubUrl":"https://github.com/BabylonJS/Babylon.js/blob/0592b347b8a4ee0236089ea86a749cacfdb266d8/packages/dev/core/src/Physics/v2/physicsShape.ts#L54-L90","documentation":"The PhysicsShape (v2) constructor requires the scene to have a physics engine. Unlike the constraint constructor it silently returns if scene is missing, but if the scene exists without an engine (`scene.getPhysicsEngine()` falsy), it throws because shapes need the plugin to create plugin-side data.","triggerScenarios":"`new PhysicsShape(options, scene)` where physics was never enabled on that scene — `scene.enablePhysics(gravity, v2Plugin)` not called, called on another scene, or disabled before shape creation.","commonSituations":"Creating shapes before async Havok initialization completes; passing the wrong scene (e.g. a UI/overlay scene); tests creating shapes on bare scenes.","solutions":["Call `scene.enablePhysics(new Vector3(0,-9.81,0), new HavokPlugin())` before creating shapes","Ensure the same scene instance is passed to both enablePhysics and the PhysicsShape constructor","Await Havok wasm initialization before any physics object construction"],"exampleFix":"// before\nconst shape = new PhysicsShape({ type: PhysicsShapeType.BOX }, scene); // throws\n// after\nawait HavokPhysics().then(havok => scene.enablePhysics(new Vector3(0,-9.81,0), new HavokPlugin(true, havok)));\nconst shape = new PhysicsShape({ type: PhysicsShapeType.BOX }, scene);","handlingStrategy":"validation","validationCode":"if (!scene.getPhysicsEngine()) {\n  throw new Error('Physics must be enabled before creating a PhysicsShape');\n}\nconst shape = new PhysicsShape(options, scene);","typeGuard":"function canCreatePhysicsShape(scene: BABYLON.Scene): boolean {\n  return !!scene.getPhysicsEngine();\n}","tryCatchPattern":"try {\n  const shape = new PhysicsShape(options, scene);\n} catch (e) {\n  if (e.message.includes('No Physics Engine')) {\n    // enable physics with a v2 plugin, then retry\n  }\n}","preventionTips":["Enable physics before any shape/body/constraint construction","Keep one canonical scene for physics; avoid passing overlay scenes","Structure boot as: await Havok -> enablePhysics -> build objects"],"tags":["physics","initialization","babylonjs"],"backgroundTag":"physics-engine-not-enabled","analyzedSha":"0592b347b8a4ee0236089ea86a749cacfdb266d8","analyzedAt":"2026-08-30T15:11:20.442Z","schemaVersion":2},"datasetVersion":"2026-08-30T18:17:15.746Z"}