0 votes

For example, in GDScript it would look like this:
onready var node = $"../Node"

But how to do something like this in C#...?

Godot version 3.5.2
in Engine by (23 points)

1 Answer

0 votes

onready is just syntax sugar, in Godot 3.X you have to do this manually by putting your code to _Ready method of you node:
public Node node; public override void _Ready() { node = GetChild<Node>("my/path/to/node"); }
There is a better way of importing nodes in Mono in Godot 4. You can simply export Node and drag and drop it using GUI. Then it will be available even before _Ready() is called.
[Export] public Node node;
You can try this example in Godot 3.X, but I' not sure if this feature was cherry-picked to 3.X branch.

by (1,650 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.