Eray Erdin
Eray Erdin

Reputation: 3179

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

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

Upvotes: 0

Views: 1107

Answers (1)

Calinou
Calinou

Reputation: 949

When I GetNode, do I actually access these runtime nodes?

You can use GetNode to access nodes created at runtime. Just make sure to do it not too early if the node is actually being added after the _Ready callback is called.

Many built-in Godot nodes will instance child nodes (mainly complex GUI controls such as GraphEdit.)

Upvotes: 1

Related Questions