Reset all scene data

Hey everyone,

When moving from 1 scene to another the last scene data is not getting cleared.

Is there a way to reset / flush the scene data?

Hi, Nishant!
I have the same problem, and i just delete the data before i transition to another scene.
I’m also wondering how to do it correctly.

Hey Dani,
That’s exactly what I have been doing. couldn’t find anything in the phaser’s documentation as well.

Which data do you mean? And how are you changing scenes?

Hi Samme,

I mean the scene or class data / variables.
for ex:

class ABC extends Phaser.scene() {
constructor(data) {
        super(data);
    }
create() {
       this.mainContainer = this.add.continer(0, 0);
    }
}

I have created a container in the create() method and when switching back to class ABC from some other class the value of mainContainer is not undefined beacause of this I have to clear the all data using a custom method.

I am using start(key,[, data]) to change the scene.

If you restart the scene then the new value of this.mainContainer will overwrite the old one when create() is repeated. But you can cleanup with

function create () {
  // …
  this.events.once('shutdown', () => {
    this.mainContainer = null;
  });
}