Error "Uncaught TypeError: scene.getUniqueId is not a function" when calling function "BABYLON.MeshBuilder.CreateLineSystem()"

In your code we find the following lines:

var createScene = async function() {
    var scene = new BABYLON.Scene(engine);
    ...
}
...
scene = createScene();
scene.then(returnedScene => {
    sceneToRender = returnedScene;
});

So the scene variable receives two values, the one returned by new BABYLON.Scene(engine) and the one returned by createScene(). The first value is an object of class Scene, while the second is a Promise. We need both values, so we have to assign those values to different variables, scene and scenePromise, and we have to move the declaration of scene outside the createScene function:

var scene = null;
var createScene = async function() {
    scene = new BABYLON.Scene(engine);
    ...
}
...
var scenePromise = createScene();
scenePromise.then(returnedScene => {
    sceneToRender = returnedScene;
});

The error this._scene.getUniqueId is not a function was due to the fact that the value of scene that we passed to the method CreateSphere was a Promise object, while this method requires a Scene object.

1 Like