Browse Source

Merge pull request #108684 from simpkins/unique_name

Fix releasing the old unique name when renaming a Node
Thaddeus Crews 1 month ago
parent
commit
4b844f06ca
1 changed files with 6 additions and 5 deletions
  1. 6 5
      scene/main/node.cpp

+ 6 - 5
scene/main/node.cpp

@@ -1416,10 +1416,15 @@ void Node::_set_name_nocheck(const StringName &p_name) {
 
 
 void Node::set_name(const StringName &p_name) {
 void Node::set_name(const StringName &p_name) {
 	ERR_FAIL_COND_MSG(data.tree && !Thread::is_main_thread(), "Changing the name to nodes inside the SceneTree is only allowed from the main thread. Use `set_name.call_deferred(new_name)`.");
 	ERR_FAIL_COND_MSG(data.tree && !Thread::is_main_thread(), "Changing the name to nodes inside the SceneTree is only allowed from the main thread. Use `set_name.call_deferred(new_name)`.");
+	ERR_FAIL_COND(p_name.is_empty());
+
 	const StringName old_name = data.name;
 	const StringName old_name = data.name;
+	if (data.unique_name_in_owner && data.owner) {
+		_release_unique_name_in_owner();
+	}
+
 	{
 	{
 		const String input_name_str = String(p_name);
 		const String input_name_str = String(p_name);
-		ERR_FAIL_COND(input_name_str.is_empty());
 		const String validated_node_name_string = input_name_str.validate_node_name();
 		const String validated_node_name_string = input_name_str.validate_node_name();
 		if (input_name_str == validated_node_name_string) {
 		if (input_name_str == validated_node_name_string) {
 			data.name = p_name;
 			data.name = p_name;
@@ -1428,10 +1433,6 @@ void Node::set_name(const StringName &p_name) {
 		}
 		}
 	}
 	}
 
 
-	if (data.unique_name_in_owner && data.owner) {
-		_release_unique_name_in_owner();
-	}
-
 	if (data.parent) {
 	if (data.parent) {
 		data.parent->_validate_child_name(this, true);
 		data.parent->_validate_child_name(this, true);
 		bool success = data.parent->data.children.replace_key(old_name, data.name);
 		bool success = data.parent->data.children.replace_key(old_name, data.name);