New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PackedScene won't save nodes added to non-root nodes #90823
Comments
The feather added to the duck's sprite is not saved/loaded because the sprite's owner is the duck instance, and the owner value isn't being updated in The Changing the _set_owner_recursive function to use |
@aaronp64 using I will be verifying this in the main project, but in the meantime, can you explain why |
Okay, I found a problem with changing You can verify this using the "print orphan" button. With the MRP it seems to create an orphan of the sprite. With my main project it creates a huge cascade of orphans probably because the node tree is deeper with more inappropriate set owner operations. I remember someone warning me once that if a node already has an owner, setting it to something else will cause orphans to be created when the save file is loaded so naively setting simply adding
takes us back to square one where some of the labels are not saved |
So it looks like the orphans are due to the PackedScene seeing that the Duck object came from Duck.tscn. When it loads back in, it uses that file, and loads its children in from there. But if we set the owner to the Pond before saving, the PackedScene also saves the Duck's child nodes separately, so there's two copies to load, and one gets orphaned. It might be possible to have PackedScene handle the orphan case, or be able to skip a node and include its children, which would work with your original MRP, but I don't know enough about it to tell if either of those options makes sense - someone more familiar with the PackedScene logic would have to advise on that. I did find a way to get everything saved/loaded without orphans (at least, it seems to work for the MRP), though it feels like there should be a simpler way to do this. Changing
If you don't need the original scene_file_path values, you can leave out the old_paths dictionary, and just clear out the old values. If you want to set them back after saving, you can loop through the dictionary keys and do something like |
Tested versions
v4.2.stable.official [46dc277]
System information
Godot v4.2.stable - Windows 10.0.22631 - GLES3 (Compatibility) - Intel(R) Iris(R) Plus Graphics (Intel Corporation; 27.20.100.9664) - Intel(R) Core(TM) i7-1065G7 CPU @ 1.30GHz (8 Threads)
Issue description
When saving with
PackedScene.pack()
, child nodes that are added at run time to nodes which are not the root of a scene will not be saved regardless of what owner they have.Code in MRP:
Note that in the MRP, the
owner
of all saved nodes is set by a recursive call in main.gd, but the exact way the owner is set does not matter.Steps to reproduce
with MRP:
Minimal reproduction project (MRP)
PackedScene save test.zip
The text was updated successfully, but these errors were encountered: