[SOLVED] Game Restarting

I want my game to restart when the player dies, but I don’t know what code can reset the game. This also includes destroyed enemies being reanimated, so I can’t just teleport the player to starting position.

The most clumsy way.

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

What does that do to the computer? Also, what is to be put into the callback?

Please use API reference. Im really glad to help anybody, but I can’t write the whole game for you.


Anything you want to change when scene was loaded… Decrease player’s store, I don’t know.

I want the game to be fully restarted, though, for now.

Oh, okay.


Thank you, that was all I wanted. Although, is there a way to reload the game without reloading the page?

Yes, but you need to handle the state. You potentially just reload the scene but there are some drawbacks to that.

It’s better for you to handle what needs to be reset in terms of game state, data and the source.

Like Mike was saying, this can include but not limited to:

  • Setting the game score to 0
  • Moving the player entity back to start
  • Disabling/Enabling entities
  • etc.

How can i find scene_id

Not sure why you ask it here as it is off-topic, but I think you can find the scene ID in the url of your browser, when you open the scene in the editor.

1 Like