Last scene not deleted completely

Hey guys, my last hierarchy is not being deleted completely, i copied code from switch scene pc reference, although there is some issue either in my code or in scene, here is a code which should be working and delete the last scene:

to test out the game linked with the issue here is a link:

Open the scene, wait about 5 seconds to roller objects to spawn and then press Spacebar to skip the level and you will see rollers in the water not being deleted. (Which should be deleted)

Hi @smokys,

What happens if you replace the first line with this?

var oldHierarchy = ('Roller');

Testing your game it seems that when you load and add a scene to the main hierarchy, that isn’t named Root but Roller.

1 Like

Hello, i tried to replace a line but that didnt destroy anything at all, so i just added that in new line and tried to destroy 2 objects Root and Roller but that didnt helped and it is the same.


The issue with the roller is that it’s being added to the app root object, not the scene root so when you delete the scene, the spawned rollers are not children of the scene root object and therefore don’t get destroyed.

Change it to:

RollerSpawner.prototype.update = function(dt) {
    this.timer += dt;
    if(this.timer >= this.waitTime){
    var instance = this.objectToSpawn.clone();
    this.timer = 0;

And that will add it to trap_01 entity.

1 Like

Thanks, that worked perfectly :slight_smile: