Trying to get es6 Havok working, odd error

I am trying to initialize a Havok plugin using es6 conventions and following this example:

But for some reason I’m getting this error when trying to run my code:

My imports look like:

and Im doing a loading function like this:

Im not really sure what I am doing wrong, it looks like await havokModule in the example is simply returning a new HavokPlugin with no arguments, and Im just kind of at a loss of how this works?

Also scene.enablePhysics is trying to say it does not exist on the Scene class, which is confusing me as well.

Could use just a little bit of insight on what I am doing wrong here.

Ive tried this too:

Just a guess, but wouldn’t you need a boolean as first parameter of HavokPlugin and you miss “new”-operator? This is the constructor declaration:

new HavokPlugin(_useDeltaForWorldStep?: boolean, hpInjection?: any): HavokPlugin

Maybe also consider:

I tried that as well, I’m running typescript so I get all those warnings.

And in in the example they are initializing it as a module without a new or arguments. Which is kinda confusing. In the example from the docs there are two different accessible methods that act different, and I’m not sure what’s the correct usage.

I’m thinking I’ll just do the separate module method and match one for one with the docs instead of doing it on a single document.

You are right. I am irritated too because there are two HavokPlugins used, one from v2-directory and one as havokModule referencing to:

But where is the HavokPhysics/PhysicsEngine?
Also what is preTasks = [havokModule] ?

1 Like

Haha see! Yeah it’s confusing AF.

HavokPlugin should not be in “@babyonjs/havok”

I tired that as well initially.

but ill do that again now.

I still get a magic word error

Like zim zim zalabin work mother F*@#$

Maybe it has something to do with webpack, I’m not sure.
I’ve had a few other minor problems with vite as well, but they’ve all been resolved

I have to say that this part is really confusing, maybe it’s easier and more pleasant to use the cdn method to bring in havok

Here is my setup as its not a super simple process… most of this was kit bashed from the docs + forum posts where others stumbled on the setup too.

You will also need the webworker WASM in your webpage root. It seems to generate on first install of havok’s package (and on updates) in your root distro folder. If you need it let me know.

----havok.ts there is nothing else in this ts except the below----

// HAVOK initialization by RaananW
import HavokPlugin from "@babylonjs/havok";
export const havokModule = HavokPlugin();

—Everything below is in the main engine initialization class—

import "@babylonjs/core/Physics/physicsEngineComponent";
import { havokModule } from "./havok";

---in the main engine initialization constructor----

let preTasks = [havokModule]; // FYI pretasks never gets directly called, this just loads the module to memory

public async init(){
… more obviously
rb.scene.enablePhysics(null, new HavokPlugin(true, await havokModule)); //<–HERE Initialized HAVOK to my rb.scene
… more obviously

You’re right, but it feels like you’re complicating things here, and it really boils down to this.

    import Havok from "@babylonjs/havok"
    import {HavokPlugin} from "@babylonjs/core"

    //on init 
    scene.enablePhysics(null, new HavokPlugin(true, await Havok()));

Ima try this tomorrow, and if it does not work Ill try @Calsa’s solution.

Thanks I thought I was losing my mind with this, but y’all made me realize its not as cut and dry as first thought.

This does not work, it results in the same magic word error.

I’ve created a react project from scratch, and it’s working fine.

1 Like

This means that there is no problem with this way of writing, the problem may be with webpack.

I’m not a build specialist like @RaananW , but I believe what preTasks is doing here is “forcing” the module that imports the plugin to run, and further here: babylonjs-webpack-es6/src/index.ts at master · RaananW/babylonjs-webpack-es6 ( it’s waiting for the instantiation to be complete.

1 Like

I think its because we are not initializing it in the scene initialization. I bet if we moved its init to that part of the codebase it would work.

1 Like

This was always critical for me to get things working. It needs to be in your init() before anything else for the module to properly load. My code may have looked “overly complex” (and yes, the process could use simplified!) but otherwise things don’t work and instead you get lots of strange errors.

the syntax seems to be correct. I’ll pull the project and experiment with it a bit, i want to understand why it doesn’t work