Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | FaDaQ |
For example, in GDScript it would look like this:
onready var node = $"../Node"
But how to do something like this in C#…?
Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | FaDaQ |
For example, in GDScript it would look like this:
onready var node = $"../Node"
But how to do something like this in C#…?
Reply From: | AlexTheRegent |
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 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.