how do i re-spawn or restart a game

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By leftstickgame

okay i have a 2d platformer vary simple it got a moving character and a tile map but i don’t know how to re-spawn a character i am vary new and was hopping someone would help with this

also it would be vary helpful of nodes I need to do this
i’m using a a kin character

:bust_in_silhouette: Reply From: Zylann

Respawning depends on what you really want in detail.

Here are the approaches I know:

  1. Just reposition the player at the beginning (spawn point or whatever) by remembering its initial state in its script. I do this in my game for all dynamic objects because it’s faster than reloading the entire level, however it can be harder to implement if there are many dynamic objects. I put all respawnable objects into a group, and then do get_tree().call_group to call a function I made on all of them to execute their specific respawn logic.

  2. Reload the entire scene. It’s the opposite of 1), so all states will be reset. Any state to “remember” will need to be stored outside the scene (in an autoload singleton for example) and reapplied after the scene is reloaded, if needed. It is the simplest way if you just want to “forget and restart” the game. To do this, you can use get_tree().reload_current_scene().

There was an existing question about solution 2)

thanks for the help

leftstickgame | 2018-06-28 23:14

You can also change the scene to what it’s currently on.

boston2029 | 2022-07-16 22:58