How to add a child to an instanced scene (in code) without making its other children visible in the editor?

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

I’m writing a plugin that instances lots of user-made scenes and nodes and arranges them in the scene tree in the editor. When adding children to an already-instanced scene using code, it causes that scene’s children to become visible in the scene tree panel, even though the Editable Children setting is disabled.

I’ve been adding children using <parent>.add_child(<scene or node>) and setting the owner to get_tree().edited_scene_root.

This is an example of a simple scene that might be instanced:
example instanced scene

This is what the scene tree looks like after my plugin builds the tree. The scene from the previous screenshot is instanced, and the Node3D is added as a child. note that the Sprite3D child node from the instanced scene is visable:
tree after building

This is an example of what I would expect the scene tree to look like after running the plugin. No instance children are visible, but multiple instances are parented to each other, along with a Node3D added at the bottom. I made this scene by manually instancing and dragging nodes in the editor to re-parent them:
manually parented scene

My question is: how can i replicate the same behavior i get from doing things manually using code? Have I missed something important, or am I doing things in the wrong way?

I’ve tested this in Godot 3.5.1 and 4.0 (beta 4), and the results are the same.

Thank you for your time!

Have you ever got to the bottom of this? I’m looking for something similar

overcrookd | 2023-01-22 14:29