{"record":{"id":"22f17a77e2642b0f","repo":"BabylonJS/Babylon.js","slug":"no-physics-engine-available-22f17a","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/physicsConstraint.ts","lineNumber":51,"sourceCode":"     */\r\n    public _initOptions?: PhysicsConstraintParameters;\r\n\r\n    /**\r\n     * Constructs a new constraint for the physics constraint.\r\n     * @param type The type of constraint to create.\r\n     * @param options The options for the constraint.\r\n     * @param scene The scene the constraint belongs to.\r\n     *\r\n     * This code is useful for creating a new constraint for the physics engine. It checks if the scene has a physics engine, and if the plugin version is correct.\r\n     * If all checks pass, it initializes the constraint with the given type and options.\r\n     */\r\n    constructor(type: PhysicsConstraintType, options: PhysicsConstraintParameters, scene: Scene) {\r\n        if (!scene) {\r\n            throw new Error(\"Missing scene parameter for constraint constructor.\");\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\r\n        this._physicsPlugin = physicsPlugin as IPhysicsEnginePluginV2;\r\n        this._options = options;\r\n        this._type = type;\r\n    }\r\n\r\n    /**\r\n     * Gets the type of the constraint.\r\n     *\r\n     * @returns The type of the constraint.\r","sourceCodeStart":33,"sourceCodeEnd":69,"githubUrl":"https://github.com/BabylonJS/Babylon.js/blob/0592b347b8a4ee0236089ea86a749cacfdb266d8/packages/dev/core/src/Physics/v2/physicsConstraint.ts#L33-L69","documentation":"The PhysicsConstraint constructor (v2 physics API) requires a physics engine already attached to the scene. Babylon.js stores the engine on the scene (created via scene.enablePhysics()); if absent, the constructor throws rather than silently creating a non-functional constraint.","triggerScenarios":"Calling `new PhysicsConstraint(type, options, scene)` on a scene where `scene.getPhysicsEngine()` returns null/undefined — i.e. `scene.enablePhysics(gravity, plugin)` was never called (or was called on a different scene).","commonSituations":"Forgetting to enable physics before creating joints/constraints; creating constraints in a scene copy or loaded scene different from the physics-enabled one; disabling physics via `scene.disablePhysicsEngine()` earlier.","solutions":["Call `scene.enablePhysics(new Vector3(0,-9.81,0), new HavokPlugin())` (or the v2 plugin of your choice) before constructing the constraint","Verify the scene instance passed to PhysicsConstraint is the physics-enabled scene, not another scene","Check that physics initialization (e.g. async Havok wasm init) has completed before creating constraints"],"exampleFix":"// before\nconst constraint = new PhysicsConstraint(Physics6DoFConstraint, options, scene); // throws\n// after\nscene.enablePhysics(new Vector3(0, -9.81, 0), new HavokPlugin());\nconst constraint = new PhysicsConstraint(Physics6DoFConstraint, options, scene);","handlingStrategy":"validation","validationCode":"if (!scene.getPhysicsEngine()) {\n  throw new Error('Enable physics before creating constraints: scene.enablePhysics(gravity, v2Plugin)');\n}\nconst constraint = new PhysicsConstraint(type, options, scene);","typeGuard":"function hasPhysicsEngine(scene: BABYLON.Scene): boolean {\n  return !!scene.getPhysicsEngine();\n}","tryCatchPattern":"try {\n  const constraint = new PhysicsConstraint(type, options, scene);\n} catch (e) {\n  if (e.message.includes('No Physics Engine')) {\n    scene.enablePhysics(new BABYLON.Vector3(0,-9.81,0), new BABYLON.HavokPlugin());\n  }\n}","preventionTips":["Always enable physics during scene bootstrap before any v2 physics object creation","Await async plugin init (Havok wasm) before constructing constraints","Pass the same scene instance used for enablePhysics"],"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"}