Returns
OK on success,
ERR_INVALID_PARAMETER if the
node is
null, or
ERR_UNCONFIGURED if the
node is already inside the scene tree.
Note: Operations happen in the following order when
change_scene_to_node is called:
1. The current scene node is immediately removed from the tree. From that point, [method Node.get_tree] called on the current (outgoing) scene will return
null.
current_scene will be
null too, because the new scene is not available yet.
2. At the end of the frame, the formerly current scene, already removed from the tree, will be deleted (freed from memory) and then the new scene node will be added to the tree. [method Node.get_tree] and
current_scene will be back to working as usual.
This ensures that both scenes aren't running at the same time, while still freeing the previous scene in a safe way similar to [method Node.queue_free].
If you want to reliably access the new scene, await the
scene_changed signal.
Warning: After using this method, the
SceneTree will take ownership of the node and will free it automatically when changing scene again. Any references you had to that node will become invalid.