But when I call get_array() from another function like this:
onready var singleton = get_node("/root/singleton)
func _ready():
var array = singleton.get_array()
it returns null. Same result with other values inside my array (I filled it with integers for testing purposes).
No matter, what I try, array remains null and I run out of ideas what I could possibly do to fix this.
I would appreciate any hints or alternative ways to solve this.
B) are you sure your singleton node is already ready when your “another function” is ready? As I don’t see a point of onready var(s) in singleton? Change it to just var.
I do autoload it in the project settings. Sorry, if i did not make this clear.
B) The file which calls the other function is a singleton too. Could this be the issue here?
The issue is you are making two singletons depend on each other. This is a bad design decision, because it’s harder to figure out which one will initialize first.
If you really want to do it this way, I suppose singletons will initialize and be ready in the order in which they appear in the singleton list, because “singletons” are in fact just nodes siblings of the current scene, under the root, which happen to be created in that order.
You can however make it order-independent by removing onready from your variable declarations. This will make the array initializer run when the singleton is created, before it is added to the tree and made ready.