Best way to add a child node to a non-root node of an instanced scene in editor?

Godot Version

Godot 4.1.1

Question

Hi, sorry if this problem has been asked somewhere before and I’ve missed it.

I’m currently working on a UI for my game within which I have drop-down sections for different categories of buttons the user can press - not ‘dropdown’ like the OptionButton node, instead very similar to the dropdowns in the properties pane (with the different categories like Layout/Localization/Tooltip/etc… that can be opened).

I’ve made the dropdown tabs their own scene that I can just make instances of (since it has it’s own script and container and such inside of it, and I want to create multiple tabs) but then I run into the issue of each of the tabs being their own self-contained scene. When they’re their own scene, I can’t put the button nodes into the tab’s container since the container is a child node and not visible when an instance of the scene is created in another scene.

I can think of a few ways around this, such as using a script at startup to place them in the correct spots or by enabling ‘Editable Children’ and placing them in the container that way, but I’d rather have them be visible in-editor and I’m not sure what the ‘proper way’ to do this is, or if I’m going about this in completely the wrong way.

Here’s the tab’s scene, with a few example buttons for what I want the structure to look like for the instances (I don’t want them as part of the scene itself, though, since they’d be different for each scene):
image
Here’s the instances, where I can’t access the child container:
image

Any advice would be appreciated, thank you!

I don’t think you can manually put nodes in a scene instance, in your main scene.

If I’m understanding your question correctly, this should work for altering scene instance trees

var scene_instance = $Tab1

var scene_instance_Tab = scene_instance.get_node("path/to/Tab")

scene_instance_Tab .add_child("node you want to add")

If you need to use the button from inside the child just export a button variable in the tab script, place the button anywhere (as a tab child also if you want) and add the referent to that button from the editor.

This way you can make use of that “external” button from your tab script.

Thanks for the help! The problem with this approach is that I’m using control nodes and I want the button to be the child node of a specific container, so that it is placed in the correct position.
Your solution is probably the solution that I’m going to go with, since I can just have some code that changes the parent of the button in ready() or something, but I was hoping that there was a way to do this such that the button was in the correct part of the tree in-editor.

Thank you for your reply, but that’s not what I’m trying to do. It’s hard to explain, but basically I’m wondering if there’s a way to set up a scene so that I can drag-and-drop a node from the editor and place it as the child node of a child node in an instanced scene.