[Havok ] New plugin physics "HK" is not defined

I wanted to try this new Havok physics engine which is an incredible engine. But my first try failed.

Maybe I rushed too quickly and not everything was deployed.

I get an error here:

const havok = new BABYLON.HavokPlugin(true); // Error hpInjection
scene.enablePhysics(new BABYLON.Vector3(0, -9.81, 0), havok);

I added the file: HavokPhysics_umd.js

And I have this error :

caught (in promise) ReferenceError: HK is not defined
at new HavokPlugin (babylon.max.js?1682022887:218628:39)

did you add Havok?

Yes, I added it locally from the zip

it has to go first. can you share a repro?

PG is working: PhysicsV2 Add Bodies | Babylon.js Playground (babylonjs.com)

So you should miss one reference somehow


In the playground it works.

I saw this on the forum: Should I also add this?

globalThis.HK = await HavokPhysics();

Maybe that’s my oversight. Because it is not indicated in the documentation that this must be added.

That should not be the case. @Cedric @carolhmj @RaananW

In the meantime please use your hack (to define HK). We will fix that asap


Should be soon fixed here Havok Plugin Documentation and Instantiation · Issue #13765 · BabylonJS/Babylon.js · GitHub


Is there no node-ish way to add Havok atm?

edit: Found @babylonjs/Havok - I assume that’s it?


yep :slight_smile:

You can see an example here :blush:

there is no change though - it still says

HK is not defined
Call Stack
 new HavokPlugin

Do I need to import the HavokPlugin from @babylonjs/core or HavokPhysics from @babylonjs/havok ?

Check the code example, it will explain everything.
I’ll write the full docs tomorrow
You need to initialize the engine and pass it as a variable to the plugin itself. Second variable.

Full docs tomorrow, promised :grin:

1 Like

I corrected it like this at home :

async createScene()

const gravity = new BABYLON.Vector3(0, -10, 0);
const hk = await HavokPhysics();
const babylonPlugin =  new BABYLON.HavokPlugin(true, hk);
scene.enablePhysics(gravity, babylonPlugin);

add the HavokPhysics_umd.js and HavokPhysics.wasm files in the same directory locally

And in the htaccess file I put
AddType application/wasm wasm

And it works


Just following up on this one:

Using Havok and the Havok Plugin | Babylon.js Documentation (babylonjs.com)