-
-
Notifications
You must be signed in to change notification settings - Fork 22k
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 Node duplicate
mapping of child properties.
#96018
Conversation
In my case, I get the "Child node disappeared while duplicating" message when I'm using duplicate() for a scene with dynamically added objects. By default, the duplicate function sets the DUPLICATE_USE_INSTANTIATION flag, which is not compatible with dynamically modified scenes (#92829). I think this means the original problem with GraphEdit is not in the 'duplicate' function. |
Yes, before this commit, the "Child node disappeared while duplicating" error appears whenever internal nodes / nodes added by scripts are duplicated (depending on the exact node tree layout, possibly also a crash). GraphEdit adds internal nodes when instantiated: godot/scene/gui/graph_edit.cpp Lines 2775 to 2793 in db76de5
This commit fixes the property mapping so that regardless of internal nodes, it will still copy the properties correctly. This fixes the duplicate() behavior on GraphEdit nodes as a byproduct. The internal nodes being skipped mentioned in #92829 seems to be expected behavior, and is in another function: Lines 2719 to 2721 in f1d43ed
|
Just coming by to say this PR doesn't work either, breaks on dynamically created objects, so for it to work like it used to it should actually only be: for (int i = 0; i < p_copy->get_child_count(); i++) {
Node *copy_child = p_copy->get_child(i);
ERR_FAIL_NULL_MSG(copy_child, "Child node disappeared while duplicating.");
_duplicate_properties(p_root, p_original->get_child(i), copy_child, p_flags);
} |
This code won't work as-is because PR #89442 fixes this by converting the function calls to One thing to note: Lines 2979 to 2980 in 2c136e6
Can you check if, on the master branch, |
@0xcafeb33f here's the thing, neither of the PRs solve dynamically created objects. PR #89442 doesn't change a thing when it comes to that, this one also somewhat doesn't work because it works on some dynamic added objects (like At this point I believe the regression might be somewhere else. |
@wagnerfs Thanks for sharing the error messages. You said it breaks on |
@0xcafeb33f it's a little late around here already, I'll most likely debug the |
Okay so as I expected, if (!descendant->get_owner()) {
continue; // Internal nodes or nodes added by scripts.
} So it'll always fail when Oh, the PR here is actually giving me crashes, probably because it's still trying to duplicate a property of a child that simply doesn't exist, I guess that's why I got a crash with the I personally don't understand why preventing the user to have a node they added through code themselves from being duplicated, and adding several steps to make it work like adding owner and all those shenanigans. |
@wagnerfs I tried to reproduce your issue but wasn't able to. Minimum reproduction project: duplicate-error.zip. If you are able to reproduce the issue, please open a bug report and tag me. Per the above discussion supporting #89442 instead, I'm closing this PR. |
In Godot 4.3, the way the
duplicate
function copied properties was changed. This results in many error messages when any Node with internal nodes as children is duplicated, as there is not a one-to-one correspondence between the original and copied children indices. Instead, Node paths need to be used, as they are when duplicating signals. This commit fixes the log spam when duplicating Nodes with internal children by finding the correct corresponding child to copy properties to.Fixes #92880 . Please cherrypick to 4.3 if possible.
P.S. this is my first pull request, please let me know if any of the metadata is incorrect.