Help I can't check with a global variable when it's game over and problem with GUI..."RESTART SCENE"

Hello everyone a few days ago I asked the question of how to restart a scene and I can restart it by changing the variable that contains the scene, the issue is that the UI does not work correctly I have a code with a Boolean variable checking if I can restart or not, the topic is that this variable when restarting the level stops working or exists, I do not understand how to debug this, the issue of asynchronous confuses me a lot.

var puedoReiniciar = true;
var canvas: HTMLCanvasElement = document.getElementById("renderCanvas") as HTMLCanvasElement;;
var engine: BABYLON.Engine = new BABYLON.Engine(canvas, true);
//para que la ventana se redimensione
window.addEventListener("resize", function () { //agrego el evento para que constantemente se acutalice el navegador
engine.resize();
});

var escenaJuego:BABYLON.Scene = Escena1(engine,canvas) as BABYLON.Scene;
; 

//////BOTON REINICIAR//////////BOTON REINICIAR//////////BOTON REINICIAR///////
var botonReiniciar: UIBotones = new UIBotones();
var nuevoBoton = botonReiniciar.BotonReiniciarScene(escenaJuego);
nuevoBoton.onPointerUpObservable.add(function() {

escenaJuego = Escena1(engine,canvas);//CHANGE SCENE  <---------------------

this.puedoReiniciar = false;
});
//////////////////////////////////////////////////////////////////////////////
escenaJuego.onReadyObservable.add(() =>
{
console.log(this.puedoReiniciar)
if (this.puedoReiniciar == false) nuevoBoton.isEnabled = false;;
if (this.puedoReiniciar == true) nuevoBoton.isEnabled = true;    
})

//Esto es el bucle principal de renderizado procesa la escena;
engine.runRenderLoop(function () { 
escenaJuego.render();
});

Video showing that when I restart the interface disappears, but it continues to work and the variable also ceases to exist.

I have been trying for several days but I cannot find the way.
If you work for the development of the engine please add a function in the scene to restart it easily since it does not seem something so simple in babylon.In engines like godot Engine or Unity this is quite simple because it is something very necessary, another topic that I see a lot It is difficult to pause a game, it would be nice if the scenes have a function to handle these things easily.

I leave the complete project in case anyone wants to try it and tell me why this problem happens.
flappy bird babylon.zip (1.4 MB)

I want to continue with this technology but I am finding many basic problems that are very difficult, however it has many advantages such as a “flappyBird3D weighs only 7MB”, this in Godot Engine can weigh 40MB.
Please help!!! :sob:

Answer can be found on a dupp thread as we completely missed this one :frowning: Help Problems restarting a scene. How to restart a scene correctly?..onReadyObservable does not work

1 Like