Adding Child of Instanced Scene into another Child

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

I’m wanting to create code in GDscript that populates a horizontal container with the sprites in scenes. These scenes are stored in an array. I got the panels working, but I’m not sure how to go about moving/adding the sprite to the created panel, or if this is even possible. This is what I have:

extends HBoxContainer
export (Array, PackedScene) var Arsenal 

onready var panel = load("res://src/GUI/ArsenalPanel.tscn")

func _ready():
		for x in Arsenal:
			var panel_inst = panel.instance()
			var scene_inst = x.instance()
			var sprite = scene_inst.get_node("Base") # the sprite to display
			
			sprite.centered = false
			add_child(panel_inst)
:bust_in_silhouette: Reply From: exuin

I’m guessing you want a new node for each panel? Just call .duplicate() on the sprite to get a new node, and then add it as a child to the panel.

Yes! Ahg I’m facepalming because I didn’t realize you could just call the add_child function from the instance; I misunderstood add_child_below_node by thinking ‘below node’ meant you selected a node for the object to be a child of. Instead, it’s the order of children. Thanks!

Cyanic Cipher | 2021-10-13 17:59