From 18cdb3c0d78bf9976b7179bbbf318ccf3d8fe266 Mon Sep 17 00:00:00 2001 From: matheusmdx Date: Tue, 28 May 2024 18:54:32 -0300 Subject: [PATCH] Fix error after create a new animation in an empty AnimationPlayer --- editor/plugins/animation_player_editor_plugin.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/editor/plugins/animation_player_editor_plugin.cpp b/editor/plugins/animation_player_editor_plugin.cpp index 62369cc2c1b..794f6190bb1 100644 --- a/editor/plugins/animation_player_editor_plugin.cpp +++ b/editor/plugins/animation_player_editor_plugin.cpp @@ -547,13 +547,18 @@ void AnimationPlayerEditor::_animation_name_edited() { } break; case TOOL_NEW_ANIM: { - String current = animation->get_item_text(animation->get_selected()); - Ref current_anim = player->get_animation(current); Ref new_anim = Ref(memnew(Animation)); new_anim->set_name(new_name); - if (current_anim.is_valid()) { - new_anim->set_step(current_anim->get_step()); + + if (animation->get_item_count() > 0) { + String current = animation->get_item_text(animation->get_selected()); + Ref current_anim = player->get_animation(current); + + if (current_anim.is_valid()) { + new_anim->set_step(current_anim->get_step()); + } } + String library_name; Ref al; library_name = library->get_item_metadata(library->get_selected());