Godot Version
Replace this line with your Godot version
v4.3.stable.mono.official [77dcf97d8]
Question
Ask your question here! Try to give as many details as possible
Is there any more convenient way to get Node nodes in C#
Replace this line with your Godot version
v4.3.stable.mono.official [77dcf97d8]
Ask your question here! Try to give as many details as possible
Is there any more convenient way to get Node nodes in C#
You can use a member variable with the export attribute and then set it in the editor just by dragging the desired node. C# exported properties — Godot Engine (stable) documentation in English
A major benefit is that the code still works even if you move the node to somewhere else in the scene, since the reference doesn’t depend on the path.
Here’s how I set up controls:
public partial class MyWindow : Window
{
...
private Button ClipboardButton;
...
public override void _Ready()
{
ClipboardButton = (Button)FindChild("ClipboardButton");
ClipboardButton.Connect("pressed", new Callable(this, "OnClipboardButtonPressed"));
}
private void OnClipboardButtonPressed()
{
}
}
or just make scripts on buttons and connect them to game systems, via events, delegates or signals.