Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | JulioYagami |
I wanted to know what does happen to the old scene when we change to a new scene?
Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | JulioYagami |
I wanted to know what does happen to the old scene when we change to a new scene?
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())