Node references that survive node renaming

Godot Version

v4.3

Question

Hello, I’ve been looking into Godot today and test it for a future project. Not a game per se but an interactive presentation. I was looking into referencing and these seem to break a lot. If I use $“…/Name”, this will break if I rename the node. If I use %Name, this will break if I rename the node.

More over I’m not sure that nodes names are their actual “script_name”, are they? Maybe I’m see it wrong but when connecting signals, the functions seem to have other names.

I also have seen people suggesting to use variables with @onready to then just update a single variable not all mentions in the code, but if a node is rename, this variable still breaks.

alt text

I did see a tip to use

@export var your_variable: NodeType

alt text

But this is failing. Maybe I’m missing some extra bits of info on how to implement this. And how to use said reference in another node’s script.

So ideally what I would like to have is:

  • Change node name.

  • Script referencing it, still works.

Thanks

The one recommending @export var your_variable: NodeType meant for you to replace your_variabel with an appropriate varible name, tbut like before, and NodeType to your node’s type, in your case `TextureButton

@export var tbut: TextureButton
1 Like

This little video made it more obvious how to use @export:
https://www.reddit.com/r/godot/comments/vtq9kw/new_game_changing_feature_in_godot_40_export_node/

alt text

Good catch I were able to make it work with Node but I guess that’s because it’s a parent class of TextureButton but using the specific type is prolly more assertive and filters things from the menu.

alt text

Thanks

Best to use the parent-est class you can, better auto completion and under-the-hood optimizations.

1 Like