Why is it that when I change a Resource in one script and then check the changes in another, there are no changes in this other script?

Godot Version

Godot 4.2.2

Question

When I change one variable in a Resource (let’s call it days), through one script, then when I try to find this changed variable using another script, it is shown in its original form.

Example:

Script №1:

extends Node

var asd = preload("res://my_resurse").days
asd = 2
print(asd)

Output: 2

Script №2:

extends Node

var asd = preload("res://my_resurse").days
print(asd)

Output: 0

Resources are unique, so they have different values. If you want to access an variable that is same no matter what you access it from, use static variables or autoloads

1 Like

Thanks! Now I have figured out how to properly synchronize Resource between scenes (using static files).

Or create a new resource of the custom resource type in the editor(right click the filesystem and click create new resource, then select your resource from the drop down(note that you need to specify a class name in the script after the extends keyword but before everything else)), set the variables, and then for those who need those variables, assign that resource. It allows you to have one value for a lot of scripts, but unlike static vars, you can use other resource instances to also keep other values. It’s quite a bit complicated, so check the docs.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.