Node Order and Ownership is not preserved when adding inherited scene

Godot Version

4.4.1-Stable

Question

I have an inherited scene who’s scene tree is this:

This scene is not loaded when the game starts running. This is a scene that is instantiated and added to the scene tree during runtime. Once the scene is added to the tree, using the “remote” tab of the editor, I can see the following scene tree nodes:

As you can see, the order is incorrect, which very much impacts how things are laid out. Also, importantly, the ownership is not retained. The UI components are not nested underneath “Content” Vertical Box as they should be.

Is there any way to address this? Is there something I’m missing? It seems like when add_child is called, it adds the Background->MarginContainer->Content UI nodes correctly and nested correctly. But then then remaining nodes are added as root level siblings. Is this some funkiness due to the scene inheritance?

This likely has to do with the code you’re using to instantiate it.

Okay, I’ve posted the code below for posterity. Resources I found online seem to indicate this is the correct way, unless I’ve missed something?

NOTE: In this sample code, “path” is a PackedScene.

# Load next scene
# Instaniate scene
current_scene = path.instantiate()
	
# Add it to scene as a child of root
slide_content_node.add_child(current_scene)

Looks good. Never seen this happen.

Where is it getting two video player nodes from?

I think this or something similar can happen when the base inherited scene changes and has overlapping names with the new nodes of the derived scene, maybe try re-saving your scenes.

1 Like

That was it! Something weird must have happened and inheritance didn’t get updated. Must have left it in a semi-broken state. What a weird issue.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.