What does happen when we change a scene?

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

I wanted to know what does happen to the old scene when we change to a new scene?

:bust_in_silhouette: Reply From: Zylann

I wrote an extensive answer to this in an older question, and how it relates to singletons: https://forum.godotengine.org/41523/how-to-keep-all-choice-in-one-scene-to-other-scene

Godot 3 (and 2) games run in a single scene tree, for which the root is a Viewport (the screen).
Your current scene is simply instanced as child of the root node. Singletons nodes (auto-loads) are instanced as siblings of the current scene, which is why they remain available.

When you use change_scene(), Godot essentially removes the node containing your current scene, and replaces it with the next one.

Put simplified, in script terms:

var current_scene = root.get_node("MyCurrentScene")
current_scene.queue_free()
root.add_child(next_scene.instance())