initialization problem with exports

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

Hye everyone,

I have several exports of this type (7 in all) :

export (Array, String, FILE, "*.tscn, *.scn")  onready var _ref_SettingNodes
export (Array, String, FILE, "*.tscn, *.scn")  onready var _ref_DialogNodes
export (Array, String, FILE, "*.tscn, *.scn")  onready var _ref_VariableNodes

The problem is that it doesn’t detect all of them as if the initialization didn’t have time to be done.

var _ref_NodesMenu : Dictionary
func _ready() -> void:
    _ref_NodesMenu = {
			    _ref_BaseNodes:, _base),
			    _ref_SettingNodes:, _setting),
			    _ref_DialogNodes:, _dialog),


func Init():
    var idx =0
    print("_ref_NodesMenu : ")
    for ref in _ref_NodesMenu :
	    print("ref : ",ref)
	    idx +=1

The first two have a node not the last and it gives this:

_ref_NodesMenu : 
ref : [res://addons/dialogue_nodes/nodes/CommentNode.tscn]
ref : []

the second is empty and the third one is not even detected… The onready is done before the _ready, right?

Good Day,

:bust_in_silhouette: Reply From: Gluon

onready defers to creation of the variable (or constant) until after the node has been assigned to the tree so removing onready would actually initialize your variables sooner.

I had tried without but it doesn’t change anything. Do you know if there is a way to force the initialization before the _ready?

patatra | 2022-11-15 14:57