Skip to content
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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions editor/gui/scene_tree_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Copy link
Member

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.


if (!is_scene_tree_dock) {
p_node->set_name(new_name);
Expand Down
5 changes: 5 additions & 0 deletions scene/main/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1188,6 +1188,11 @@ String Node::validate_child_name(Node *p_child) {
_generate_serial_child_name(p_child, name);
return name;
}

String Node::validate_child_name(Node *p_child, StringName p_name) {
_generate_serial_child_name(p_child, p_name);
return p_name;
}
Comment on lines +1191 to +1195
Copy link
Member

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.

#endif

String Node::adjust_name_casing(const String &p_name) {
Expand Down
1 change: 1 addition & 0 deletions scene/main/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,7 @@ class Node : public Object {

#ifdef TOOLS_ENABLED
String validate_child_name(Node *p_child);
String validate_child_name(Node *p_child, StringName p_name);
#endif
static String adjust_name_casing(const String &p_name);

Expand Down