Godot Version
4.3
Question
I am trying to dynamically add children to a node during _ready. I load the scene to add, instantiate it, and add the child, but it is not listed afterward when I list the children, nor is it found later on in the program’s run when I specifically look for the child.
Rust Code Snippet:
let scene = load::<PackedScene>("res://source/match/units/traits/Selection.tscn");
let mut node = scene.instantiate().unwrap();
let unit_var = self.base_mut().get(StringName::from("radius"));
node.set(StringName::from("radius"), unit_var);
godot_print!("Add: {}", node.get_name());
self.base_mut().add_child(node);
for child in self
.base()
.find_children_ex(GString::from("*"))
.recursive(false)
.done()
.iter_shared()
{
godot_print!("Child: {}", child.get_name().to_string());
}
Output:
Add: Selection
Child: Geometry
Child: CollisionShape3D
Child: Movement
Child: Sparkling