playcanvas / engine

JavaScript game engine built on WebGL, WebGPU, WebXR and glTF
https://playcanvas.com
MIT License
9.52k stars 1.33k forks source link

Static models with an assigned batch group disappear when reloading the scene #3229

Closed davidpuetter closed 1 year ago

davidpuetter commented 3 years ago

Description

Static models in a scene that have a Batch Group assigned disappear when the same scene is destroyed and reloaded, regardless of whether or not the batcher has ran.

Project Link Forum Post Link

Upon first load, you'll see a couple of plane entities laid out. The outer circle of planes have no batch group assigned, whereas anything inside the circle have a single batch group assigned with its layer set to World. Once you reload the scene by pressing 'L', you'll notice that all the planes that had a batch group assigned disappear from the scene, and the ones without a batch group remain in place as expected.

Tested on Windows 10 (2004 - 19041.985) using Google Chrome v91.0.4472.77, and Firefox v89.0, PlayCanvas v1.42.0

Steps to Reproduce

  1. Create a few entities around the scene and set them to be Static
  2. Create a new Batch Group and give it the World layer
  3. Assign the new batch group to the entities
  4. Load the game, see that all entities load fine
  5. Use SceneRegistry.loadSceneHierarchy to reload the scene and destroy the old hierarchy
  6. Observe that the entities with a batch group have disappeared.

Screenshots

Screenshot 1 - Before reloading the scene Iy78cxYn

Screenshot 2 - After reloading the scene EIodJzAK

mvaligursky commented 3 years ago

I tried looking into this, but have not found an issue .. it would need more time and deeper investigation, perhaps another time.

As a workaround (not the same behaviour, I understand) would be to remove the previous scene before new one gets loaded.

SceneSwitchButton.prototype.loadScene = function() {
    var oldHierarchy = this.app.root.findByName('MyScene');
    var scene = this.app.scenes.find("GameScene");
    oldHierarchy.destroy();

    this.app.scenes.loadSceneHierarchy(scene.url, function (err, parent) {
        if (!err) {
        } else {
            console.error(err);
        }
    });  
};
yaustar commented 2 years ago

A smaller repo of this project as another client ran into this issue: https://playcanvas.com/project/971118/overview/adding-batch-group-entity-at-rt