What does get_tree() return?

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

I have a bit of a understanding problem what exactly get_tree() returns.

In the documentation I’ve read that it returns the SceneTree, but what exactly does that mean? Does it return all nodes that I have in my current scene or does it return my root-node?

Maybe someone could help me clarify this :slight_smile:

:bust_in_silhouette: Reply From: omggomb

SceneTree is a class. See the reference docs for it: https://docs.godotengine.org/en/stable/classes/class_scenetree.html#class-scenetree. There is also a tutorial page for it in the docs: https://docs.godotengine.org/en/stable/getting_started/step_by_step/scene_tree.html

So get_tree() returns an (or better the) instance of this class. The instance itself then has means to access the nodes inside it. SceneTree itself is not a node, but a descendant of MainLoop. Think of it as a manager class that takes care of updating and managing all the nodes in it while running in an infinite loop until the player exits the game (get_tree().quit()).

ah I understand, thank you for the detailed answer!

YAGU | 2021-03-05 13:30