I have a singleton, correctly added to Autoload in Project Settings. Moreover, I have used it in several scenes and it is working fine.
Now, I want to instance a node that has to load this singleton. I provide you a minimal working example for my problem.
This the script that I have. It is not a singleton. From here, I will instance
var packed = preload("res://scene_with_singleton.tscn")
var scene = packed.instance()
var a = 5
scene.init_stuff(a) #Error comes from here
Then, in the
scene_with_singleton.tscn I have:
#my_singleton.gd was added to Autoload
singleton = get_node("/root/my_singleton")
When I do this a get a
Attempt to call function 'call_stuff' in base 'null instance' on a null instance.. I suspect that the problem lies in the order Godot is loading the stuff, but I don't know how to overcome it.
I have read this, which is exactly the same problem I am having, but I don't understand which is the solution.
Thanks for your help.