Hi
I'm trying to build a paperdoll system, constructed from a parent node and sprite2D children of the node representing the layers. I am using @tool so that I can customise the various attributes of the character and save these out as separate scenes for NPCs etc. The parent node has a dictionary containing a reference to it's children. The children are created in code during the parents _ready() function. I use a dictionary for quick access to the "layers" for when I need to swap out textures or parameters of the sprites shaders etc (using resources that I have created for various components). Having been at this for a couple of weeks and happy with the results, my code has stop working! I know its probably something really simple but I think I must have gone code blind because I can't resolve the issue. My dictionary has the keys but now has <empty> for the values.
Here is some example code that replicates the issue:
@tool
extends Node2D
@export var spriteNodes: Dictionary
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
for i in 10:
var node: Sprite2D = Sprite2D.new()
node.name = "Node"+str(i)
add_child(node)
node.owner = get_tree().edited_scene_root
spriteNodes[i] = node
I have also tried creating the nodes from within a child of parent, so they are then visible to the parent, just in case this is a _ready() ordering issue, however the problem persists. Hopefully there is something painfully obvious that I am missing.