How i can change nodes of object from autoloading script?

Godot Version



I create a test scene that include background ColorRect, Timer and Santa node(this include some nodes and UI node, that have a Label node named “Best_int_label”. And i create an autoloading script “data” that have a code:

extends Node

var best_score = 0
var file

func _ready():
if FileAccess.file_exists(“data.txt”):
file =“data.txt”, FileAccess.READ)
best_score = int(file.get_as_text())

func _process(delta):

func new_score(score):
if score > best_score:

func new_best(score):
best_score = score
file =“data.txt”, FileAccess.WRITE)
#HERE I NEED TO CHANGE TEXT OF “test/santa/ui/best_int_label”

How i can change text of “test/santa/ui/best_int_label” at last line of this script? I cant do this with using “get_node(“test/santa/ui/best_int_label”)”, because godot give an error that node not found.

I want to make sure that when game opening, it reads data from “data.txt”. And when player set new best score, game save it to data.txt. Maybe i can do this in different way?


Manually Hardcode the node path is not the best practice, because the tree may change and your path will not automatically update it
instead try use Global Event Bus Signalling
emit the signal and connect the signal at UI script. it should do the work

example how to do it:
in your Santa Script:

func _ready():
	EventBus.update_ui.connect(func(_score):print("replace this print to the function that update your UI: ",_score))

in your “data”.gd when you want to try to update the score with the signal:


in the EventBus script AutoLoad:

extends Node

signal update_ui(new_score)
1 Like

Big thanks bro

1 Like