Hi. If i set script to autoload, engine creates a node with script attached to. However, what happens to singleton node when i replace root node with get_tree().change_scene("res://lets_say_there_is_scene_in_this_folder_with_this_name") ? I wonder if singleton node get reparented or wiped out and replaced.I need to keep variables and some functions between menu and levels and i really want to know what happens to singleton node. I also want ask you if I can get multiple instances of singleton node by entring the scene where node already was what may happens in Unity with dontDestroyOnLoad flag (That does not mean i want it to happen. Vice versa, it was big problem in Unity). Thank -Garrom

When you change_scene() or change_scene_to(), the singleton (or autoload) nodes are preserved. The function does not replace root node. It just changes active scene, without touching singleton nodes.

@arthur said: When you change_scene() or change_scene_to(), the singleton (or autoload) nodes are preserved. The function does not replace root node. It just changes active scene, without touching singleton nodes.

So if is everything inside tree, the tree what get replaced, where is singleton node then ?

The editor can display the tree graph during runtime. Look at the debugger tabs in Godot 2.1, or in the scene dock in Godot 3.0 while the game is running.

@GarromOrcShaman said:

@arthur said: When you change_scene() or change_scene_to(), the singleton (or autoload) nodes are preserved. The function does not replace root node. It just changes active scene, without touching singleton nodes.

So if is everything inside tree, the tree what get replaced, where is singleton node then ?

The engine is smart enough to just change node of current scene. It does not touch the root node or any of its children that is not the current scene node. Example:

root
|- singleton 1
|- singleton 2
L current scene node

When you call change_scene(), the only node that will be changed is current scene node. The other nodes (root, singleton 1 and singleton 2) won't be affected at all.

5 years later