how to get_node from another scene

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

I’am making an option button, and i want to change the color of a label that is in another scene, this is my actual code

extends HBoxContainer

export var node = ""

func _on_OptionBox_focus_entered():
	get_node("OptionLabel").add_color_override("font_color", Color(1,1,0.3,0.8))
	get_node("MinusButton").add_color_override("font_color", Color(1,1,0.3,0.8))
	get_node("PlusButton").add_color_override("font_color", Color(1,1,0.3,0.8))
	get_node(node).add_color_override("font_color", Color(1,1,0.3,0.8))

Is the other scene in the same scene tree as this script?

Ertain | 2022-01-14 20:42

no, it’s not

VinicOliver8394 | 2022-01-14 20:50

:bust_in_silhouette: Reply From: Gluon

If its not in the same scene tree you will need to have a autoload script to pass the information from one scene to another.

Create a script and go into the project options. You will see autoload options. In this set that script to autoload. This will mean you will always load that script in every other scene which loads.

Now you can put a variable in that script, perhaps an array with all the colour settings you want. When someone changes it in this scene amend the array in the autoload script. The when you load the script with the label in use the settings in the autoload scripts variables to set the colour in the _ready function.