Skip to main content
The SceneTree is one of Godot’s most important classes. It manages the hierarchy of nodes in your game, controls the game loop, handles scene switching, and provides powerful tools for organizing and querying nodes through groups.

What is the SceneTree?

The SceneTree manages the active tree of nodes in your game. It’s automatically created when Godot starts and serves as the default MainLoop implementation, making it responsible for:
  • Managing the node hierarchy
  • Processing node callbacks (_process, _physics_process)
  • Handling scene loading and switching
  • Managing node groups
  • Controlling game pause state
  • Providing access to the root node
Every node in your game can access the SceneTree using get_tree(), but only if the node is currently in the tree.

Accessing the SceneTree

Calling get_tree() on a node that isn’t in the scene tree will generate an error and return null. Always check with is_inside_tree() first if you’re unsure.

The Root Node

The root node is the topmost node in the scene tree, always of type Window:

Scene Management

The SceneTree provides several methods for loading, changing, and reloading scenes.

Changing Scenes

1

Change Scene from File Path

The most common way to switch scenes:
2

Change Scene from PackedScene

Use a preloaded scene for faster switching:
3

Change Scene to Node Instance

Switch to an already instantiated scene:
When changing scenes, the current scene is removed from the tree immediately, then freed at the end of the frame. The new scene is added after the current frame completes.

Scene Change Order

Understanding the order of operations during scene changes is crucial:

Reloading the Current Scene

Unloading a Scene

Pausing the Game

The SceneTree controls whether the game is paused:
When the game is paused:
  • Physics processing stops
  • _process() and _physics_process() may not be called (depends on process_mode)
  • Collision detection pauses

Process Modes

Nodes can control how they behave when the game is paused:
Set your pause menu’s process_mode to PROCESS_MODE_WHEN_PAUSED so it can respond to input while the game is paused.

Node Groups

Groups allow you to organize nodes by category and operate on multiple nodes at once.

Adding Nodes to Groups

Nodes are automatically removed from all groups when freed. You rarely need to manually remove nodes from groups.

Querying Groups

Calling Methods on Groups

One of the most powerful features is calling methods on all nodes in a group:
By default, call_group() acts immediately on all nodes, which may cause performance issues with large groups. Use call_group_flags() with GROUP_CALL_DEFERRED for better performance.

Group Call Flags

Node Paths

Node paths are used to reference nodes within the scene tree:
Absolute paths start with /root/ and work from the root node. Relative paths work from the current node.

Scene Tree Timers

The SceneTree can create one-shot timers:

Timer Parameters

Quitting the Game

On iOS, apps should not programmatically quit. The quit function is ignored on that platform.

Practical Example: Game Manager

Here’s a complete game manager that uses SceneTree features:

Scene Tree Signals

The SceneTree emits useful signals:

Best Practices

1

Use Groups for Categories

Organize nodes into logical groups (enemies, UI, collectibles) for easy batch operations.
2

Prefer Deferred Group Calls

Use GROUP_CALL_DEFERRED when calling methods on groups to avoid issues with nodes being freed during iteration.
3

Set Process Modes Appropriately

Make sure UI and pause menus use PROCESS_MODE_WHEN_PAUSED so they work while the game is paused.
4

Await scene_changed

When changing scenes, await the scene_changed signal if you need to access the new scene immediately.
5

Use Autoload for Game Management

Create autoload singletons that use SceneTree features to manage game state globally.

Next Steps

Nodes and Scenes

Learn about the building blocks managed by SceneTree

Resource System

Understand how Resources work with scenes