godotengine / godotengine/godot

Nodes instanced at run-time and added as children to non-root scene nodes do not persist when using PackedScene Pack and Instantiate in certain scenarios

Open
#103,406 1 comment 0 reactions 0 assignees View on GitHub
bug needs testing topic:core topic:dotnet
Dominant language
C++
Stars
117k
Forks
26.8k
PR merge metrics
PR metrics pending

Description

### Tested versions

- Reproducible in v4.3.stable.mono.official [77dcf97d8]

### System information

Godot v4.3.stable.mono - Windows 10.0.22631 - Vulkan (Forward+) - dedicated NVIDIA GeForce RTX 4080 (NVIDIA; 31.0.15.3640) - AMD Ryzen 9 7950X 16-Core Processor (32 Threads)

### Issue description

I have a complex scene hierarchy in the game I'm building that includes instancing various different PackedScenes and adding them as children at runtime in various points in said hierarchy. While attempting to implement a save/load system for my scenes using PackedScene I noted that after instantiating the PackedScene I was missing many (but not all) of these nodes. After some debugging I was able to pinpoint the reason for the missing nodes: any instanced nodes added as a child to a *non-root node* within a specific scene will not persist properly when using Pack and Instantiate *IF* the scene in question is also dynamically instanced and added to a node. If these nodes are instead added to the root node of the specific scene, or if the root node of the scene in question is Packed directly, they will persist.

I am setting the owner of all instanced nodes to the node that is passed to the Pack function per the documentation. However, I've also tested a number of other permutations where I do not set the owner, set the owner to the direct parent scene root, use Export properties to attempt to force it to be included, and so on.

### Steps to reproduce

I am including a sample project that was built to demonstrate this issue. Just running the game will display the main scene in which there are four dynamically instanced scene hierarchies. In the top row, I am creating the scene hierarchy and then attaching the final interior node (the Godot icon) to the *root* of the last scene in the hierarchy, before using Pack and Instantiate to create and attach a copy (this works as expected). In the bottom row, I'm doing exactly the same steps except I'm attaching the final interior node to a child node within the last scene in the hierarchy instead. The bottom-right section shows that using Pack and Instantiate on this setup results in the Godot icon being missing.

![Image](https://github.com/user-attachments/assets/ae417d8e-eb38-49a2-8688-58cac57413e3)

### Minimal reproduction project (MRP)

[packedscenebug.zip](https://github.com/user-attachments/files/19030842/packedscenebug.zip)

Contributor guide

Open the contributing guide

Research direction

Start by running the attached packedscenebug.zip minimal reproduction project and compare the top and bottom dynamically instanced scene hierarchies. Trace the PackedScene Pack and Instantiate workflow for nodes owned by non-root scene nodes. Done means the nested runtime-added Godot icon persists after packing and instantiating, matching the root-child case.

Written by the indexing model from the issue text.

Assessment

Tech stack
godot
Domain
game-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.