+1 vote

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

in Engine by (452 points)

2 Answers

+1 vote
Best answer

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.

by (29,088 points)
edited by
0 votes

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.

by (341 points)
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 Frequently asked questions and 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 [email protected] with your username.