How to reference a var node in a script (per instance)?

65 views Asked by At

Am moving from Unity to Godot. There, you can put in the inspector the public variable and change it per instance, but I don't know how to do this in Godot.

I tried using public Node/Node3D and selecting in Godot's inspector, but it didn't even appear. Apparently (correct me if am wrong), you need to use onready vars or something like that (I still don't understand it), but that way you will only be able to reference the same node (gameObject) in all instances of the script, instead of a different one per instance.

1

There are 1 answers

3
Theraot On

To export variable to the inspector from C# in Godot, you need to add the [Export] attribute to them.

You should be able to do that with your Node variable:

using Godot;

public partial class ExportExample : Node3D
{
    [Export]
    Node3D node;
}

See C# exported properties.