summaryrefslogtreecommitdiffstats
path: root/editor/gui
diff options
context:
space:
mode:
authorkobewi <kobewi4e@gmail.com>2024-11-12 20:29:10 +0100
committerkobewi <kobewi4e@gmail.com>2024-11-12 20:29:10 +0100
commitad8ede2411008e1915505b149c9fcec0104404a5 (patch)
tree8c8c7b06a1f9acd023119fadf28d3e6fb634a9fb /editor/gui
parentcb411fa960f0b7fdbd97dcdb4c90f9346360ee0e (diff)
downloadredot-engine-ad8ede2411008e1915505b149c9fcec0104404a5.tar.gz
Restore original root name if renaming instance to empty
Diffstat (limited to 'editor/gui')
-rw-r--r--editor/gui/scene_tree_editor.cpp13
1 files changed, 12 insertions, 1 deletions
diff --git a/editor/gui/scene_tree_editor.cpp b/editor/gui/scene_tree_editor.cpp
index c11da5dfdb..e89912d5bc 100644
--- a/editor/gui/scene_tree_editor.cpp
+++ b/editor/gui/scene_tree_editor.cpp
@@ -1098,8 +1098,19 @@ void SceneTreeEditor::rename_node(Node *p_node, const String &p_name, TreeItem *
// 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();
+ if (new_name.is_empty() && p_node->get_owner() != nullptr && !p_node->get_scene_file_path().is_empty()) {
+ // If name is empty and node is root of an instance, revert to the original name.
+ const Ref<PackedScene> node_scene = ResourceLoader::load(p_node->get_scene_file_path());
+ if (node_scene.is_valid()) {
+ const Ref<SceneState> &state = node_scene->get_state();
+ if (state->get_node_count() > 0) {
+ new_name = state->get_node_name(0); // Root's name.
+ }
+ }
+ }
+
if (new_name.is_empty()) {
- // If name is empty, fallback to class name.
+ // If name is still empty, fallback to class name.
if (GLOBAL_GET("editor/naming/node_name_casing").operator int() != NAME_CASING_PASCAL_CASE) {
new_name = Node::adjust_name_casing(p_node->get_class());
} else {