How to get a node from a script in another scene

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By LoneDreemurr

Hey, i’ve readed a lot of topics but none came to an solution. I am making a menu for the game and i need to have access to other nodes that are in other scenes.

The code i am making:
##Player.gd
`
onready var globals := GlobalWorld.title_label

...

func _on_StartButton_pressed() -> void:
on_menu = false
$Head/Camera.current = true
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
globals.text = str("Hello")


pass`

this is the script i want to pick the nodes from the main scene, that have the following code:
##World.gd

extends Spatial

onready var start_button: Button = $Control/Buttons/StartButton
onready var options_button: Button = $Control/Buttons/OptionsButton
onready var controls_button: Button = $Control/Buttons/ControlsButton
onready var quit_game_button: Button = $Control/Buttons/QuitGameButton
onready var title_label: RichTextLabel = $Control/Title/RichTextLabel

I’m using the Autoload if you may wonder, and i tried using the “get_node”, simply what happens here is that globals.text simply returns a null_instance (apparently).

details of the error: E 0:00:04.332 get_node: (Node not found: “Control/Buttons/StartButton” (relative to “/root/GlobalWorld”).)
<Erro C++> Method failed. Returning: nullptr
<Origem C++> scene/main/node.cpp:1465 @ get_node()
World.gd:3 @ _ready()

im not really sure of whats happening, but keep in mind i want a node that is in another scene

:bust_in_silhouette: Reply From: SQBX

None of these lines will get nodes

onready var start_button: Button = $Control/Buttons/StartButton
onready var options_button: Button = $Control/Buttons/OptionsButton
onready var controls_button: Button = $Control/Buttons/ControlsButton
onready var quit_game_button: Button = $Control/Buttons/QuitGameButton
onready var title_label: RichTextLabel = $Control/Title/RichTextLabel

This is because “Control” in not a child of “GlobalWorld.” Instead, delete this lines and write this:

var control: Control

Notice that we didn’t set the variable yet. Next, add a script to the “Control” node (if you haven’t already) and add this to the _ready function:

func _ready():
    GlobalWorld.control = self

Now you can reference the children of “Control” from wherever you’d like. So this line:

onready var globals := GlobalWorld.title_label

Would become:

onready var globals := GlobalWorld.control.get_node("Buttons/TitleLable")

And then everything should work as expected.