How to properly restart a game?

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

Hi! I’m experimenting with a Godot and am at a point where I want to restart the whole game by calling get_tree().reload_current_scene() but whenever I do that, all previously instantiated scenes remain in the tree and cause problems. Tried change_scene() but that had the same effect. I probably don’t understand how the reloading works but there is no explanation in the official docs, or at least none that I could find.
What is the best way to restart the game so it behaves like it’s been opened for the first time? Thanks for any advice!

:bust_in_silhouette: Reply From: PhantomPixel

I found that deleting the instances and reloading the scene works for me

Ex:

var fishdelete = get_tree().get_nodes_in_group("Fish")
for fishthings in fishdelete:
	fishthings.queue_free()
get_tree().reload_current_scene()

Godot version: 3.3.2

:bust_in_silhouette: Reply From: Paar

Alright, I know what’s going on. I have mistaken the get_tree().root for a method that returns the topmost node in the project tree, but it is not obviously. Right now I’m adding all node instances to the root and they’re sibling nodes to the main node, that’s why they stay there even after reloading the current scene.