Skip to content

Commit

Permalink
Fix renaming a node to the name of its siblings breaking NodePath
Browse files Browse the repository at this point in the history
Also fix cases where node name was not visually updated because name was not changed

Co-Authored-By: Nông Văn Tình <[email protected]>
  • Loading branch information
ajreckof and nongvantinh committed Jan 16, 2024
1 parent 04eafd5 commit 2f69792
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
5 changes: 2 additions & 3 deletions editor/gui/scene_tree_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1051,10 +1051,9 @@ void SceneTreeEditor::_rename_node(Node *p_node, const String &p_name) {
}
}

new_name = p_node->get_parent()->prevalidate_child_name(p_node, new_name);
if (new_name == p_node->get_name()) {
if (item->get_text(0).is_empty()) {
item->set_text(0, new_name);
}
item->set_text(0, new_name);
return;
}

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

String Node::prevalidate_child_name(Node *p_child, StringName p_name) {
_generate_serial_child_name(p_child, p_name);
return p_name;
}
#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 @@ -614,6 +614,7 @@ class Node : public Object {

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

Expand Down

0 comments on commit 2f69792

Please sign in to comment.