Set it so that when you add a child to a "prefab," scene, it adds it to a specific child in the resource?

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

This is a hard one to phrase in the title, so here’s an example

level (Node with script attached)
    |_ Y-Sort

I would like to setup the above so that I have a prefab for levels that I can just drag and drop into a new scene, and it will have the Y-Sort and script attached. Problem is, to my knowledge if I add something as a child to this node, it will be added on the same tree level as “Y-Sort,” and not a child of Y-Sort.

Is there any way to set it so when I have the “level,” node used as a root node in a new scene, that all further children get set to the children of Y-Sort?

It’s kind of hard to explain, so if it’s not clear let me know and I will edit this how I can.

:bust_in_silhouette: Reply From: njamster

You could overwrite the add_child-method in the script attached your level:

func add_child(node: Node, legible_unique_name: bool = false):
$YSort.add_child(node, legible_unique_name)

Make sure the script is run in the editor as well by prefixing it with the tool-keyword. If you instance your level scene somewhere else and add a child node to it, it will now be added to the underlying YSort-node instead. However, the added nodes will not be shown by default. For this, you need to check “Editable Children” when right-clicking on the level-node you just instanced, to include the YSort-node in the tree.