+1 vote

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 :)

Godot version 3.2.3 (stable)
in Engine by (42 points)

1 Answer

+2 votes
Best answer

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()).

by (1,239 points)
selected by

ah I understand, thank you for the detailed answer!

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.