Script [undefined] has missing arguments in constructor

After changing scene hierarchy and deleting some old scripts that our team didn’t use. I have some problems with switch between scenes. Project drops down like you see on screenshot.

My code to switch scenes copied from official topic, i tried to creating new scenes without any root hierarchy - but it won’t help.

Code example:

loadScene: (sceneName, options, callback, scope) => {
        // Find the Scene Registry Item by the name of the scene
        var app = pc.Application.getApplication();
        var scene = app.scenes.find(sceneName);
        if (scene) {
            // Check if the scene data is already loaded, if it is we should assume
            // that it stay cached after we loaded the scene and added the 
            // entities to the scene graph
            var wasSceneLoaded = scene.loaded;
            try{
                            app.scenes.loadSceneData(scene, (err, scene) => {
                if (err) {
                    console.log(err);
                    if (callback) {
                        callback.call(scope, err);
                    }
                } else {
                    var sceneParent = null;

                    // Destroy all the entities on the app.root to completely remove 
                    // the existing scenes
                    var rootChildren = app.root.children;
                    while (rootChildren.length > 0) {
                        rootChildren[0].destroy();
                    }

                    // As we've already loaded the scene data, the callbacks for these
                    // functions will be called immediately
                    if (options.settings) {
                        app.scenes.loadSceneSettings(scene, function (err) {
                            if (err) {
                                reject(err);
                                callback.call(scope, err);

                            }
                        });
                    }

                    if (options.hierarchy) {
                        app.scenes.loadSceneHierarchy(scene, async function (err, parent) {
                            if (err) {
                                reject(err);
                                if (callback) {
                                    callback(err);
                                }
                            } else {
                                sceneParent = parent;
                            }
                        });
                    }
                    if (!wasSceneLoaded) {
                        app.scenes.unloadSceneData(scene);
                    }

                    if (callback) {
                        callback.call(scope, null, sceneParent);
                    }
                }
            });
            }catch(e){
                if(callback) {
                    callback.call(scope, e);
                }
            }

        } else {
            if (callback) {
                callback.call(scope, "Scene not found: " + sceneName);
            }
        }
    }

Can you post an example project please?

Sorry can’t show project because of NDA, may be i can help sharing you some more information?

The project is large with 8 scenes (locations, VFX tests etc.) i’m only changed name folders and replaced some files.

Could you strip down a fork and share? The error refers to code that isn’t shown in the post unfortunately

If you could share a published build, that would work as well

I’ve not seen this error before so hard to really tell without a repro to dig into

It’s kind a joke, but when i run public build everything is okay, not any problem, when switch scene)

So it’s only happening in the launch window/tab?

Yep, it’s happening only when i run it from editor(

Can you try forking the project and stripping all the assets and code except for the scene changer and see if it still happens? If it does, please share the project and I will try to take a look

1 Like