In GDScript, I can create node variables with the following: @export var my_node: Node. Then in the inspector, I can drag an drop another node from the scene tree into that variable. However, what if I can’t see the node in the scene tree and it is inside another scene? How do I drag and drop that node that I want to reference?
Then the node isn’t guarenteed to exist from this scene so you cannot @export it, you will have to retrieve the node through other means, many use groups.
As @gertkeno said, exported variables only work with nodes visible in the current scene tree. If a node is in another scene that hasn’t been instanced yet, it can’t be assigned through the inspector. In that case, you’d need to access it through code after the scene is loaded. Using groups is a common solution; add the node to a group and find it with get_tree(). .get_nodes_in_group(). Another option is to pass the reference manually when you instance the other scene.
Thank you. The scenes are already added to the scene tree and won’t be instanced at run time. For example I would like to export a variable in my main.gd to reference a node in my Player scene. Is this still a problem?
If you export a node you can access all of it’s variables, the scene tree you posted seems straight forward. The player would @export var the_main: Node3D or use get_parent() then access what ever variable from main.gd it needs. Or do you need to enable “Editable Children” on the Player to select it’s children?
Can you state exactly what you are trying to do? Big picture what problem are you facing and why are you trying @exports to solve it?