-
-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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
Fix for "Save Branch as Scene" #45937
Conversation
What is the purpose of |
The reown function is based on the original _duplicate_and_reown which did it in the same way. I thought, I stick to that approach as it is more generalized. But you are right, in this particular case a check for null would be sufficient. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sooo the reown map should be removed. Other than that it looks ok.
Agreed, will be done! |
…plicate_from_editor, which is also used by "Duplicate" function of the SceneTreeDock - Removed Node::duplicate_and_reown method as it is not used anymore
Dear @KoBeWi, thank you for your code review and comments! I've incorporated the requested change by replacing the |
Thanks! |
Fixes #42611.
Hello Godoters! This PR is for discussion on my solution for #42611. While the PR solves the problems described in the original ticket, I'm new to the Godot engine and therefore appreciate your feedback on this solution.
Result of my analysis:
The original "Save Branch as Scene" function of the SceneTreeDock uses the
duplicate_and_reown
function of theNode
class to create a clone of the selected node, saving it to a file and then replacing the subtree by the scene instance. My analysis showed thatduplicate_and_reown
has the following flaws:_duplicate_and_reown
skips children of instanced scenes (owner check at the beginning of the method)While [1] was rather easy to fix, [2] was not easily possible, as there would have been a lot of special cases to handle, which the
duplicate_and_reown
method currently isn't aware of (e.g. changed properties of editable children, nodes added to editable children).I found out the the Node class has three "duplicate" methods:
duplicate
duplicate_from_editor
(used in SceneTreeDock's "Duplicate" function)duplicate_and_reown
(used in SceneTreeDock's "Save Branch as Scene" function, looked a bit outdated)I've checked the
duplicate_from_editor
and found out that it is aware of creating duplicates with (editable) instanced scenes. Using the "Duplicate" function in Godot v4 editor together with the MRP from #42611 showed good results. Only issue was that the "editable" flag got lost as well (but can be fixed easily).Summary of changes in this PR:
duplicate_from_editor
instead ofduplicate_and_reown
.duplicate_and_reown
as it was only used in "Save Branch as Scene" (and not exposed to scripting)AddedNode::reown
method to recursively change owners of a tree (was originally part ofduplicate_and_reown
) - use it in the modified "Save Branch as Scene" function to update the owner in the duplicated subtreeNode::duplicate_from_editor
to copy the "editable" flag of instanced childrenI'm looking forward to your feedback on these changes. :-)
PS: During development I've recognized that when saving a .tscn, Godot 4.0 writes out a script = null for each node without a script. I'm not sure whether this is a bug or a feature, but I just want to point out that this has nothing to do with the changes in this PR in case you wonder. It happens with vanilla Godot 4.0 from master branch when saving a scene.
Edit: Updated formatting + added minor clarifications
Edit 2: Updated list of changes (removed
reown
function after code review)