Can't find node through GetNode?

Godot Version

v4.2.1.stable.mono.official [b09f793f5]


I have this script:

    public override void _Ready()
        UIinstance = UI.Instantiate<Control>();
        Node CombatUI = GetNode("%UI/CombatUI");

But I’m getting an error at the second and third line, because GetNode doesn’t find the node at %UI/CombatUI.

This is probably a very silly mistake, but I can’t figure it out. Here is my hierearchy

The script is called from a node instantiated under the Characters. Am I misunderstanding how access as unique name works?

GetNode() works on a path system based on which node calls it. Your code is attempting to search for a child of your character named UI instead of the UI itself. I’m unsure if it’s different for C#, but the path for the UI in GDscript would be “/root/Test/UI/CombatUI” assuming Test is the scene’s root node.

I thought that Access as unique name allowed me to get it from anywhere, was I wrong?

Using the Unique Name with GetNode can cause issues when instanced scenes are involved (I assume the characters are instanced scenes). If you still want to use the Unique Name method instead of using the direct path, you can likely better fix your issue with this page on the Godot Docs.

have you tried just

Node CombatUI = $"UI/CombatUI";