#_init_ for nodes being added via code

1 messages · Page 1 of 1 (latest)

bold knoll
#

Hey,
I want to add UI Elements based on a variable list of entities in my save file.
Currently I just have a "prepare" function on the main script of the scene I want to add but this seems a bit dirty and I need to write some extra lines to make sure it does not execute any logic before the data has been set. Is there a way so that when I do this:

extends PanelContainer

var knowledgeUIRef = preload("res://Game/UI/KnowledgeTab/knowledge_instance_panel.tscn")

func _ready() -> void:
    for _knowledge in Save.gameStats.KnowledgeListRef:
        var newKnowledgeUI : KnowledgeInstancePanel = knowledgeUIRef.instantiate()

the "instantiate()" part prompts me to and executes the "ready" function which ideally would be the init or something else?

#

"KnowledgeInstancePanel" would be the script that is on the main node of the knowledge_instance_panel.tscn that has an init

azure sleet
#

why not just use _ready() in KnowledgeInstancePanel?

#

usually that's where you init stuff

#

I don't see anything about basic Godot mechanisms holding you back here, to me it sounds like KnowledgeInstancePanel has external dependencies and this casues side effects. Hard to tell without knowing what it does