• Godot Help
  • [C#] Easier way to get reference to nodes?

So, I'm using the C# version of godot because I know and like that programming language more than the Python-esque GDScript. But there is one thing which I envy from GDScript. That you can easily access the Node references by just clicking and dragging the node into the editor.

In c#, you always have to type out the GetNode<node type>("nodename") method.

For those who also use C#, don't you have a nice way of speeding up this process? Some Protip. 😃

  • d13 replied to this.
    [Export] private NodePath pathToNode;
    public override void _Ready() {
        Node actualNode = GetNode<Node>(pathToNode);
    }

    Don't forget to build the .NET/C# solution after adding [Export] variables to a script, as you won't be able to see them in the editor before.

      Armynator That's a pretty good idea. Is there any particular reason you use NodePath instead of referencing Node? That way if you set up the node in the editor, you don't even have to use the GetNode in the Ready method?

        gdomjan83 because exporting the Node directly isn't supported in Godot 3. In Godot 4 you can use [Export] on your Node variables directly, or keep doing it the old way with NodePath - whatever works better in your case.