-
-
Notifications
You must be signed in to change notification settings - Fork 21.1k
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 renaming a node to the name of its siblings causing exported NodePath
to point to the wrong node
#76575
Conversation
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.
This a good fix. Unfortunately this only fixes it for basic renames and do not fix it for batch rename. You should do the same here to fix it for batch rename too
|
||
String Node::validate_child_name(Node *p_child, StringName p_name) { | ||
_generate_serial_child_name(p_child, p_name); | ||
return p_name; | ||
} |
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.
I would rename this function to prevalidate_child_name
to make it clear what is the difference with the other function.
4f33a60
to
8e37cf2
Compare
While reviewing this and working on #76376 at the same time, I realized Batch Rename was too fucked up for an easy fix and would need to wait for my proper fix in the linked PR. I think you should re-focus this PR solely on fixing the original bug with only simple renames. I'm so sorry as this was my fault for bringing up Batch rename in the first place. |
I agree with you. However, the current implementation of UndoRedo does not align with the The problem is: godot/editor/rename_dialog.cpp Line 603 in 64eeb04
The |
now that #76376 is merged would you mind rebasing this to be included in 4.1 ? This should be similar to what you had done first just placed in the function |
…iblings causes the exported NodePath to point to the wrong node.
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.
I like the idea of this PR. Would you mind just renaming the function to prevalidate_child_name as i suggested in a previous commentary?
@@ -988,6 +988,7 @@ void SceneTreeEditor::_rename_node(Node *p_node, const String &p_name) { | |||
} | |||
// Trim leading/trailing whitespace to prevent node names from containing accidental whitespace, which would make it more difficult to get the node via `get_node()`. | |||
new_name = new_name.strip_edges(); | |||
new_name = p_node->get_parent()->validate_child_name(p_node, new_name); |
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.
This should be a bit above around line 981 to prevent renaming when the validated new name is the same as the current name. Take the previous line with it.
NodePath
to point to the wrong node.NodePath
to point to the wrong node
Once text editing is complete, the method
void SceneTreeEditor::_renamed()
is triggered, followed byvoid SceneTreeDock::_node_prerenamed(Node *p_node, const String &p_new_name)
. Afterward, the methodvoid SceneTreeDock::perform_node_renames(Node *p_base, HashMap<Node *, NodePath> *p_renames, HashMap<Ref<Animation>, HashSet<int>> *r_rem_anims)
is called, which ultimately leads to line 1707 where the methodp_base->set(propertyname, updated_variant);
modifies the previously set value with the new Node's name. Next, the methodvoid SceneTreeEditor::_rename_node(ObjectID p_node, const String &p_name)
is triggered to update the TreeItem in SceneTreeEditor and the Node's name. However, the problem arises in line 962:n->set_name(p_name);
when the Node's name is validated usingdata.parent->_validate_child_name(this, true);
. It is then discovered that the new name conflicts with a sibling's name, prompting_generate_serial_child_name(p_child, name);
to append a number to the renaming Node's name. Unfortunately, the value of the exported variable is not updated, causing the bug.Fixes: #76192
Fixes: #76680