How can I get the root of a scene without calling get_parent() a bunch?

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

If I have a scene like this:
1
-2
–3
—4
And I want to get node 1 from node 4 without calling get_parent() 3 times. How can I do this?

:bust_in_silhouette: Reply From: Zylann

If you want to get the root of the scene you made in the editor, you can use get_tree().current_scene.

Note: this is actually not the real root. The real root is a Viewport node representing the actual game screen, and is obtained by doing get_tree().get_root(), or get_node("/root").
current_scene is a child of this node, and autoload nodes are children of it the viewport as well.

:bust_in_silhouette: Reply From: 807

If you don´t change that in runtime or in instancing, you could use “get_owner” and it should be the scene root of the packed scene.