+3 votes

The main scene is like this:
enter image description here
So far the 'Board' node is instanced (as you can see in the image) and at the same time children of 'Board' are instanced by code script.

Can any of the children nodes of 'Board' reach the 'Game' node using the get_node() by path?

I've tried this code:

    var game=get_node("/Game")
    if game:
        print("got game")

but fails.

in Engine by (690 points)

1 Answer

+7 votes
Best answer

First of all, get_node accepts a filesystem-like path, and scenes, after they are instanced, are just nodes somewhere in the tree.

This means that you can just do get_node("../../") to get the parent of the parent node.

But... there is a slight trick. The root node is /root, and it has the currently-running scene inside it, which means that you can use /root/Game to get to the node you want.

by (1,608 points)
selected by

Oh thanks for the quick and detailed reply! I should have know it from a carefully read of documentation am examples.

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.