diff --git a/scene/2d/animated_sprite_2d.cpp b/scene/2d/animated_sprite_2d.cpp index bf3783966b16..6bd36d03fe30 100644 --- a/scene/2d/animated_sprite_2d.cpp +++ b/scene/2d/animated_sprite_2d.cpp @@ -299,16 +299,13 @@ void AnimatedSprite2D::set_sprite_frames(const Ref &p_frames) { List al; frames->get_animation_list(&al); - if (al.size() == 0) { - set_animation(StringName()); + + animation = StringName(); + if (!al.is_empty()) { + set_animation(frames->has_animation(animation) ? animation : al[0]); + } + if (!frames->has_animation(autoplay)) { autoplay = String(); - } else { - if (!frames->has_animation(animation)) { - set_animation(al[0]); - } - if (!frames->has_animation(autoplay)) { - autoplay = String(); - } } } diff --git a/scene/3d/sprite_3d.cpp b/scene/3d/sprite_3d.cpp index ffd328c37e8e..db1244bbbdf2 100644 --- a/scene/3d/sprite_3d.cpp +++ b/scene/3d/sprite_3d.cpp @@ -1112,16 +1112,13 @@ void AnimatedSprite3D::set_sprite_frames(const Ref &p_frames) { List al; frames->get_animation_list(&al); - if (al.size() == 0) { - set_animation(StringName()); + + animation = StringName(); + if (!al.is_empty()) { + set_animation(frames->has_animation(animation) ? animation : al[0]); + } + if (!frames->has_animation(autoplay)) { autoplay = String(); - } else { - if (!frames->has_animation(animation)) { - set_animation(al[0]); - } - if (!frames->has_animation(autoplay)) { - autoplay = String(); - } } }