{"record":{"id":"ce9aebfdb4c251f9","repo":"BabylonJS/Babylon.js","slug":"no-physics-plugin-available-ce9aeb","errorCode":null,"errorMessage":"No Physics Plugin available.","messagePattern":"No Physics Plugin available\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/dev/core/src/Physics/v2/physicsShape.ts","lineNumber":79,"sourceCode":"     *\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\n    }\r\n\r\n    /**\r\n     * Returns the string \"PhysicsShape\".\r\n     * @returns \"PhysicsShape\"\r\n     */\r\n    public getClassName() {\r","sourceCodeStart":61,"sourceCodeEnd":97,"githubUrl":"https://github.com/BabylonJS/Babylon.js/blob/0592b347b8a4ee0236089ea86a749cacfdb266d8/packages/dev/core/src/Physics/v2/physicsShape.ts#L61-L97","documentation":"After version validation, PhysicsShape fetches the plugin with `physicsEngine.getPhysicsPlugin()`; a falsy result means the engine object exists but carries no plugin, so no plugin-side shape data can be created and the constructor throws.","triggerScenarios":"Scene has a PhysicsEngine instance but no plugin registered — e.g. engine constructed without a plugin argument, or plugin assignment failed/was skipped during custom integration.","commonSituations":"Custom physics engine subclasses created without a plugin; failed async plugin initialization silently leaving the engine plugin-less; manually calling `new PhysicsEngine(gravity)` then attaching it to the scene.","solutions":["Always pass a concrete plugin to `scene.enablePhysics(gravity, plugin)`","Verify plugin initialization (e.g. Havok wasm) resolved before enabling physics","Assert `scene.getPhysicsEngine()?.getPhysicsPlugin()` is truthy in bootstrapping code"],"exampleFix":"// before\nscene.enablePhysics(gravity); // no plugin\nconst shape = new PhysicsShape(options, scene); // throws\n// after\nconst havok = await HavokPhysics();\nscene.enablePhysics(gravity, new HavokPlugin(true, havok));\nconst shape = new PhysicsShape(options, scene);","handlingStrategy":"validation","validationCode":"if (!scene.getPhysicsEngine()?.getPhysicsPlugin()) {\n  throw new Error('A registered physics plugin is required before creating a PhysicsShape');\n}","typeGuard":"function hasPhysicsPlugin(scene: BABYLON.Scene): boolean {\n  return !!scene.getPhysicsEngine()?.getPhysicsPlugin();\n}","tryCatchPattern":"try {\n  const shape = new PhysicsShape(options, scene);\n} catch (e) {\n  if (e.message.includes('No Physics Plugin')) {\n    // re-enable physics with an explicit plugin\n  }\n}","preventionTips":["Always supply the plugin to scene.enablePhysics","Handle plugin init failures explicitly instead of swallowing them","Unit-test scene bootstrap so the plugin is verified as attached"],"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"}