From 52d56d806de79419a30dee48f76e8653683b5726 Mon Sep 17 00:00:00 2001 From: Rindbee Date: Tue, 18 Jul 2023 13:10:58 +0800 Subject: [PATCH] Fix rename animation in SpriteFramesEditor/AnimationNodeStateMachineEditor When the name suffix grows, the old name is used if it is obtained first. Fix the case where the following error message would appear when renaming an animation. ``` ERROR: Animation '' doesn't exist. at: get_frame_count (scene/resources/sprite_frames.cpp:71) ``` (cherry picked from commit e9cd29cf228b67f3b6bf4061bd578c673c757d66) --- editor/plugins/animation_state_machine_editor.cpp | 4 ++++ editor/plugins/sprite_frames_editor_plugin.cpp | 5 ++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/editor/plugins/animation_state_machine_editor.cpp b/editor/plugins/animation_state_machine_editor.cpp index 49f073f2451f..2a7454a7a255 100644 --- a/editor/plugins/animation_state_machine_editor.cpp +++ b/editor/plugins/animation_state_machine_editor.cpp @@ -1507,6 +1507,10 @@ void AnimationNodeStateMachineEditor::_name_edited(const String &p_text) { int base = 1; String name = base_name; while (state_machine->has_node(name)) { + if (name == prev_name) { + name_edit_popup->hide(); // The old name wins, the name doesn't change, just hide the popup. + return; + } base++; name = base_name + " " + itos(base); } diff --git a/editor/plugins/sprite_frames_editor_plugin.cpp b/editor/plugins/sprite_frames_editor_plugin.cpp index 563398e5126f..420ea087fa47 100644 --- a/editor/plugins/sprite_frames_editor_plugin.cpp +++ b/editor/plugins/sprite_frames_editor_plugin.cpp @@ -948,13 +948,16 @@ void SpriteFramesEditor::_animation_name_edited() { String name = new_name; int counter = 0; while (frames->has_animation(name)) { + if (name == String(edited_anim)) { + edited->set_text(0, name); // The name didn't change, just updated the column text to name. + return; + } counter++; name = new_name + "_" + itos(counter); } EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton(); undo_redo->create_action(TTR("Rename Animation"), UndoRedo::MERGE_DISABLE, EditorNode::get_singleton()->get_edited_scene()); - _rename_node_animation(undo_redo, false, edited_anim, "", ""); undo_redo->add_do_method(frames.ptr(), "rename_animation", edited_anim, name); undo_redo->add_undo_method(frames.ptr(), "rename_animation", name, edited_anim); _rename_node_animation(undo_redo, false, edited_anim, name, name);