Aditive load of a scene finishes before loading everything

Hello there,
I am doing an aditive load of the diferent scenes of my game. On the tests and on the scenes I have done works perfectly, but I have added new scenes and with these last ones it is not working properly.

Here is the code I am using:

//function that loads aditively
SceneManager.prototype._loadSelectedScene = function () {
    if (!this._loadingScene) {
        this._loadingScene = true;

        // Remove the current scene that is loaded
        for (var iterator = 0; iterator < this.sceneRootEntity.children.length; iterator++) {
            const i = iterator
            this.sceneRootEntity.children[i].destroy();
        }

        //select the scene to load and make some adjustments for the player
        var scene = this.app.scenes.find(this._selectedSceneName);
        this.localPlayer.rigidbody.enabled = false;
        //start loading the scene
        this.app.scenes.loadSceneHierarchy(scene,
            (err, loadedSceneRootEntity) => this.OnHierarchyLoaded(scene, err, loadedSceneRootEntity)
        );
    }
};

//calback function for loading scenes aditively
SceneManager.prototype.OnHierarchyLoaded = function (scene, err, loadedSceneRootEntity) {
    if (err) {
        console.error(err);
    } else {
        //reparent the scene
        loadedSceneRootEntity.reparent(this.sceneRootEntity);

        this.app.scenes.loadSceneSettings(scene, (err) => {
            if (err) {
                console.error(err);
            } else {
                //alert("Scene loaded");
                this.app.lightmapper.bake(null, 0);
                this.app.fire('sceneLoaded', loadedSceneRootEntity);
                this.app.fire('TpLoadingScreenOFF')

                if (this._selectedSceneName == "Expo") {
                    this.app.fire('changePopup', 'introExpo')
                }

                this._loadingScene = false;
                this.localPlayer.rigidbody.enabled = true;
                this.localPlayer.rigidbody.teleport(SceneManager.Origin);
            }
        });
    }
}

In some scenes the objects are poping after doing the baking of the lights.

Hi @lrios,

Loading a scene involves loading the scene entity hierarchy. Any assets not loaded and referenced by entity components (materials, textures, models etc.) will be loaded later on e.g. when they come into view.

You can set their preload flag to true, that will ensure that all resources have been loaded when your app loads. Or add your own loading logic and find your assets e.g. by tag and load them together with your scene.

Thanks, I will be implementing a loading logic. Otherwise, mobile devices won’t be able to manage the load on VRAM.

1 Like