scene.enablePhysics isn't defined unless Inspector is imported for side effects

I’m using the latest alpha of @babylonjs/core: 4.0.0-alpha.32, and it seems that I can’t call scene.enablePhysics() with or without arguments unless I’ve also installed @babylonjs/inspector: 4.0.0-alpha.32 and included import '@babylonjs/inspector'; at the top of my file for side-effects. I get this error without it:

Uncaught TypeError: scene.enablePhysics is not a function

and indeed, if I inspect the scene object in the debugger, it appears to be a normal Babylon scene object but it’s missing the enablePhysics function.

I can’t demo this using the playground because it appears that the inspector is included by default. Not sure whether I can change that.

Is it intentional that the inspector is required to use physics?

physics is a component so we do not add it to the code by default for tree shaking purpose.

You can import the component for side effects (populating the scene with the enablePhysics function) via:


This is what the inspector does and it explains why when you use it, it works in your code. The side effects works for your entire app.

Aha, got it. I couldn’t find anything about that in the docs, but maybe I wasn’t looking hard enough. Appreciate the help!

The doc is still under preparation for side effect for the 4.0 it might explain why you did not find it :slight_smile:

1 Like