[Editor Project] Scripts not loading on SceneLoader.Append

Hi there, just started using Babylon.js, specifically using the Editor. (v.3.2.0). I’ve previously used Unity, but wanted to try out other engines to broaden my horizons.

I’ve been trying to set up my project to load between two scenes, and have followed the Explaining the Workflow documentation to the end to create a working project.

All went well, until I needed to change scenes, and the documentation mentions: “What Wasn’t Covered: How to change scenes, like in a video game”. So I’ve been digging around on my own, with some success.

I’m currently using SceneLoader.Append in a script within the editor to load in the other scene into the main scene, and the scene does get loaded in, but without any of the scripts attached to objects in the scene. The constructors are not called, and it’s just the scene with the meshes.

I think the problem lies in the OnSuccess callback of SceneLoader.Append. In the game.ts file, Extensions.ApplyExtensions gets called inside the callback function, where the Code Editor extension for that specific scene gets loaded. I tried writing the same thing in my own scene change function, but when I try to include ‘import { Extensions } from “babylonjs-editor”’ to get access to the Extensions class, the code editor says “babylonjs-editor” doesn’t exist.

I’m at an impasse at this point, as I’m not sure how to fix this, and I’ve been searching for a solution for the past day to no avail. Anybody have any idea how to get scripts from another scene working in the current scene using SceneLoader.Append, if I’m doing it right at all, or just a better way to change scenes? I could really use some help

Pinging @julien-moreau

1 Like

Hey @vUdevU :slight_smile:

Unfortunately the Editor v3 hasn’t been designed to be able to communicate with the external code :frowning:
@ozRocker had the same problem and found a way to send messages through the engine.

@ozRocker can you share the solution you found ? (even if it is ugly because of the current state of the Editor)

Anyway, I’m focusing on the V4 of the Editor which fixes this problem. You can find the downloads of the beta version here: BabylonJS Editor v4.0.0 beta · BabylonJS/Editor Wiki · GitHub

And the documentation which is still WIP: Editor/doc.md at release/4.0.0 · BabylonJS/Editor · GitHub

The v4 has been made from scratch to avoid that kind of problems and is not anymore compatible with the v3 projects.


I used window.postMessage() and window.addEventListener() to communicate with external code.

1 Like

Thanks for the quick reply @julien-moreau! I’ll look into both V4 and @ozRocker’s method. I haven’t gone too far into my project, so I can still switch to the new version without too much issues. I’ll give them both a try!