Uncaught TypeError: this._scene.getUniqueId

Hi,

I am getting this error when I am loading a javascript file from my code. I assume its related to async loading. Here I have created the scene async, but it does not fix the issue.

The error i am getting is:

Uncaught TypeError: this._scene.getUniqueId is not a function

And here is my create scene function:

var createScene = async function () {

        var scene = new BABYLON.Scene(engine);
       ...
       ...
};
        window.initFunction = async function () {
            var asyncEngineCreation = async function () {
                try {
                    return createDefaultEngine();
                } catch (e) {
                    console.log("the available createEngine function failed. Creating the default engine instead");
                    return createDefaultEngine();
                }
            }

            window.engine = await asyncEngineCreation();
            if (!engine) throw 'engine should not be null.';
            window.scene = createScene();
        };
        initFunction().then(() => {
            scene.then(returnedScene => { sceneToRender = returnedScene; });

            engine.runRenderLoop(function () {
                if (sceneToRender && sceneToRender.activeCamera) {
                    sceneToRender.render();
                }
            });
        });

This is quite popular error - TypeError: "x" is not a function - JavaScript | MDN and usually the problems are somewhere in the code.
What I can recommend is to check your promises, especially the problem line. Seems that some variable is not passed or not passed properly.

Its hard to tell without a full repro/playground scene. Javascript, in all its scriptyness makes it very easy to corrupt variables and class members with values of the wrong “type”, I’d suggest throwing some breakpoints into your scripts to make sure that this._scene is what you expect it to be, then working backwards from there.

1 Like