Attached script not loading/working with BABYLON.SceneLoader.LoadAsync (Babylon.js Editor 3.2.0)

I created a very simple scene which features a spinning cube. The cube spins through a script which has the default boilerplate (as generated by the editor) with the following addition:

public update (deltaTimeMs: number): void {
    // Your code...
    this.mesh.rotate(Axis.Y, 0.001 * deltaTimeMs, Space.WORLD)

Everything works as expected when playing the scene in the editor, but when I export it as a *.babylon scene and then load it onto my page, I only see the cube rendered without any spinning. I load the scene with the following code:

this.$BABYLON.SceneLoader.LoadAsync( //It's a Vue project
    .then(scene => {
      const camera = new this.$BABYLON.FreeCamera(
        new this.$BABYLON.Vector3(0, 0, -10),
      ); = camera;
      this.scene = scene;
      this.engine.runRenderLoop(() => {

I attached CANNON to the window object, and get no more errors. The script itself, by default, should log the mesh to the console on the start() function. It does so in the editor, but not on my page. This leads me to suspect the script may not even be present at all in the scene.

I already checked the renderloop and it seems to be working correctly. Can anyone offer some advice/insights on this?

Adding @julien-moreau for the editor :slight_smile:

Some additional info, I’ve tried the following:

  • Use Load/LoadAsync/Append/AppendAsync, all giving the same result: Cube shows but does not spin
  • Use the local Mac editor and the online editor, no difference
  • Messed around with placement of babylon.js file (in Vue, with NPM, with CDN), no difference either

The behaviorScript is present within the scene.babylon file, but it does not appear to be activated in a web page.

EDIT: Babylon Playground example: Babylon.js Playground . It loads the scene from a dropbox link. You can open it, and see that the behaviorScript is referenced in the metadata of the cube node, but it does not seem to be executed.

Hey @Arnaud_H!
You are right, the .babylon file format doesn’t support attached scripts. It is managed using the BabylonJS-editor extension package.

The documentation can be found here: Explaining the Workflow - Babylon.js Documentation
Take a look at the generated code and you’ll se that a « BabylonJS-editor-extensions » package is imported and loads the editor metadata to apply scripts, postproceses etc.


That worked! Thanks!
It may be a considerable idea to give the exporting process its own section within the resources page, I’ve been redirected to that page a few times when looking into my problem, but never went into the “explaining the workflow” section as it didn’t appear descriptively relevant just by the title.

1 Like

Good to know ! Thanks !
You are right for the name, we can find better.

Dont forget this documentation Using Code Editor - Babylon.js Documentation for the scripts if you want to go further :slight_smile:

1 Like