Skip to content

Node::get_tree() returns non-null - #1493

Merged
Bromeon merged 1 commit into
masterfrom
qol/node-get-tree-required
Feb 5, 2026
Merged

Node::get_tree() returns non-null#1493
Bromeon merged 1 commit into
masterfrom
qol/node-get-tree-required

Conversation

@Bromeon

@Bromeon Bromeon commented Feb 5, 2026

Copy link
Copy Markdown
Member

Changes Node API:

fn get_tree(&self) -> Option<Gd<SceneTree>>;

to:

fn get_tree(&self) -> Gd<SceneTree>;
fn get_tree_or_null(&self) -> Option<Gd<SceneTree>>;

Following required object APIs (#1383), we can classify Node::get_tree() in a similar way -- it's supposed to be called inside the tree. Calling it outside the tree is explicitly an error:

SceneTree get_tree() const

Returns the SceneTree that contains this node. If this node is not inside the tree, generates an error and returns null. See also is_inside_tree().

This differentiates it from other methods like get_window, get_parent, get_owner etc. which have explicit non-error branches for the nullptr return type, and thus continue to return Option.

The fallible method is now available under get_tree_or_null. Unlike before, it no longer prints an error in the None case.

@Bromeon Bromeon added quality-of-life No new functionality, but improves ergonomics/internals c: engine Godot classes (nodes, resources, ...) breaking-change Requires SemVer bump labels Feb 5, 2026
@Bromeon Bromeon added this to the 0.5 milestone Feb 5, 2026
@Bromeon
Bromeon added this pull request to the merge queue Feb 5, 2026
Merged via the queue into master with commit 3ef8f6c Feb 5, 2026
23 checks passed
@Bromeon
Bromeon deleted the qol/node-get-tree-required branch February 5, 2026 19:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking-change Requires SemVer bump c: engine Godot classes (nodes, resources, ...) quality-of-life No new functionality, but improves ergonomics/internals

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant