[SOLVED] How do I restart a scene?

Hello! When the player in my game is killed, I reload the whole site but then that resets you to the first level. I want it to be like when you get killed, to restart the scene without reloading the website page. Is there any way I can do that? Thank you!

Hi @SoySauceStudios!

You can change the scene to the same scene.

this.app.scenes.changeScene('Scene Name');

This requires you to know the name of the scene, so you need to keep track of the current scene.

var oldHierarchy = pc.app.root.findByName("Root");    
 oldHierarchy.destroy();  
        
  this.app.loadSceneHierarchy("<scene_id>.json", function (err, parent) {
      // callback     
  });

Delete the old instance and create new one will restart the whole game without reload.

This is a more complex method @techy_589, I strongly suggest to use the method I shared.

1 Like

Thank you guys it worked! Happy Halloween!

1 Like