In Godot, when I GetNode, do I access runtime nodes or the nodes of the current scene?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Eray Erdin

Today I discovered Godot actually sets up runtime nodes. You can see what I mean below:

godot debug remote nodes

When I run the game with debugging options, I can see these nodes under “Remote” tab in scene dock. So, that got me wondering… When I GetNode, do I actually access these runtime nodes?

To give an example, consider these three seperate scenes:

Foo
> foo: Node2D

Bar
> bar: Node2D

Container
> container: Node2D
>> foo: Node2D (injecting Foo)
>> bar: Node2D (injecting Bar)

In this case, Container scene is parent and importing/injecting foo and bar. So, in Foo.cs, can I access the injector, which is container node, as below:

// Foo.cs
Node2D container = (Node2D)GetNode("/root/container");

Or will this fail?


Environment

  • Godot Mono 3.2
  • Mono JIT Compiler 6.4.0
  • Manjaro 19.0.2
:bust_in_silhouette: Reply From: Eray Erdin

This seems to be the case, which means GetNode actually gets runtime nodes. That’s actually good since I plan to keep the tree consistent during the gameplay so that I can access several things such as faders and loaders.