I have a custom scene that I've built as a reusable dialog. I want any nodes added to an instance of that scene to be added to a descendant of the scene instead of the scene root. I have been able to get this partially working by overriding add_child
in the scene's script:
extends Control
@tool
func add_child(child: Node, force_readable_name: bool = false, internal: int = 0):
get_node("./button_container").add_child(child, force_readable_name, internal)
child.set_owner(self)
Any nodes added via the editor do show up in the scene preview, and if I enable "Editable Children" for the instanced scene I can see the new node in the tree (with a white label - all of the default nodes are in yellow). Once I save and reload the scene, the child node disappears. That says to me that the node isn't being placed into the tree properly, so it's not being serialized when I save the scene. I thought this may be due to the node's owner not being set correctly, but setting the child's owner to button_container
or self
doesn't change anything.
The dream state would be to have the children of button_container
listed in the scene tree editor as the children of the instanced scene.