Restarting a scene with new data

Hello,
I start my scene Game from another scene pressing a button like this:

this.startButton.on(‘pointerdown’, () => {

  this.relatedScene.scene.start(this.destination, {id: 0}); 

});

The data is loaded correctly using

init: function (data)
{
this.Id= data.id;
}

but, when the room is over i start the same scene using diferent data with

this.scene.start(this.key, { id: 3});

And the scene restart correctly, but with the same data that the first time. In my case the data is an Id that switchs between the TileMaps to use. And when the scene restarts, all the parameters restart and I can play the Game again, but with the same map.

PD: Sorry I don´t know how to copy code in the correct format :frowning:

Hi @DavidGanfornina! I have a really good example that I can’t share because it’s client work. However, what you want pretty much works well for me. For a demo-game, I had one scene that would load different levels with tilemaps depending on the data that was passed. It restarted the entire game after completing the last level:

if (this.enterKey.isDown) {
    if (this.level === this.finalLevel) {
        this.scene.restart({ level: 1 });
    } else {
        this.scene.restart({ level: this.level + 1 });
    }
}

In my create() function I have this:

create(data) {
    this.level = data.level || 1;
    // ...
}

You can have the same logic in init() as well. Also note that if you’re restarting the current scene, you can omit the key property. I’d say use a debugger to see if the key is correct and watch values for this.id. Maybe it’s being reset somewhere else?

:wave:

Try logging values at every point. It sounds like what you’re doing should work.

Be careful that you’re not using the same asset key in preload with a different asset URL. Use different keys or else remove the original asset first before reusing the key.