Hello,

From what I have learned, using the % symbol will allow you to access this node anywhere in the scene by using using the following GDScript:
%Pivot
or If I am accessing it from a script assigned to Player, I can use the $ symbol and the path:
$Pivot

I am using C#, are there any way to directly reference a node like this? Or is my only option using the GetNode function? Example:

Spatial s = GetNode<Spatial>("$Pivot");

  • I believe that the $ is a GDScript-specific feature, and not applicable to C#. The % is a general Godot feature and applicable to both GDScript and C#.

    In GDScript, they can be used in combination:
    onready var some_node: Node = $"%TheNodeName"

    The % is inside quotes since it's not built into GDScript syntax like $. The % is only a special character that can be used to begin a node name, indicating that it's a scene-unique node name.

    (The scene-unique node name feature was added in Godot 3.5.)

I believe that the $ is a GDScript-specific feature, and not applicable to C#. The % is a general Godot feature and applicable to both GDScript and C#.

In GDScript, they can be used in combination:
onready var some_node: Node = $"%TheNodeName"

The % is inside quotes since it's not built into GDScript syntax like $. The % is only a special character that can be used to begin a node name, indicating that it's a scene-unique node name.

(The scene-unique node name feature was added in Godot 3.5.)

    Can't comment on C# since I've not used it with godot and haven't used it in general in a long time. But it's worth a note that when you use $ shorthand in GDScript then you don't need the " quotation marks to encapsulate the node path.

    You do need the quotation marks in the example I provided that uses the % character. Otherwise you'll get a syntax error. (That's the case for 3.5. Maybe it's different for GDScript 2 and Godot 4.0.)

      DaveTheCoder Right, that was a failure in recalling it correct on my part, it's parenthesis that I was likely thinking of. I personally mostly stick to using get_node() typed out fully for my part.

      I always use get_node. It's not really that much more typing.

        DaveTheCoder Thanks Dave. I use c# for my day job so I am still figuring out the nuances between GDscript and C#. Your explanation clears things up.

        cybereality Also get_node() looks a lot more like programming which will help when other programmers look at your program (those that aren't familiar)

        Well I like my code to read like English, so I write my functions and logic so it makes sense when you read it. Not for other programmers, I work alone, but because I have a bad memory and can't remember code I wrote a month ago. Like if you write this:

        var player = get_node("World/Player")
        player.position.x = 100

        That makes sense in English. If you write:

        $World/Player.position.x = 100

        That looks like a mess and is nonsense.

        That's not a fair comparison.

        I prefer this:

        var player = $World/Player
        player.position.x = 100.0

        Well, sure. But I see a lot of beginners using $ all over the place for every access. If you cache your nodes at the top of a script (or with exports or with autoloads) then you are literally typing an extra 6 or 7 characters one time, not really worth the loss of readability.

        That's somewhat related to my hesitation in using scene-unique node names. It's convenient, but makes it easier to be sloppy in organizing the scene tree.

        If we were using C++, this would be possible to implement:

        $(World/Player).position.x = 100;

        🙂
        But since that seems odd, not as easy for others.
        kind of like how my vector maths class can do:
        Vec3 pos = 1, 2, 3;
        But I'd never use it because it would mess with people, I just wanted to play with comma operators for fun. 🙂

        C# does have a $, but it's meaning is string interpolation (inserting variables into positions in a string), so it's not available for redefining like in C++.