From 254fa6c6424b48a146ba6a003b796c2094191ba2 Mon Sep 17 00:00:00 2001 From: Adam Simpkins Date: Wed, 16 Jul 2025 13:52:10 -0700 Subject: [PATCH] fix releasing the old unique name when renaming a Node This fixes `Node::set_name()` to release the old unique name before performing the rename. #76560 changed the code to update `data.name` before calling `_release_unique_name_in_owner()`, causing to incorrectly try releasing the new name instead of the old name. Fixes #108683 --- scene/main/node.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/scene/main/node.cpp b/scene/main/node.cpp index 28e6f297b18..78f546bba09 100644 --- a/scene/main/node.cpp +++ b/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) { 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; + if (data.unique_name_in_owner && data.owner) { + _release_unique_name_in_owner(); + } + { 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(); if (input_name_str == validated_node_name_string) { 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) { data.parent->_validate_child_name(this, true); bool success = data.parent->data.children.replace_key(old_name, data.name);