From 578d7cd115205715f64468850e62f56e93747831 Mon Sep 17 00:00:00 2001 From: Olle Lukowski Date: Sun, 14 Sep 2025 11:14:07 +0200 Subject: [PATCH] Ensure the AnimationPlayer emits animation_finished for every animation --- scene/animation/animation_player.cpp | 10 +++++++++- scene/animation/animation_player.h | 2 ++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/scene/animation/animation_player.cpp b/scene/animation/animation_player.cpp index 8f20dd5e47f..3132a686bf9 100644 --- a/scene/animation/animation_player.cpp +++ b/scene/animation/animation_player.cpp @@ -277,6 +277,9 @@ void AnimationPlayer::_blend_playback_data(double p_delta, bool p_started) { // Finally, if not end the animation, do blending. if (end_reached) { playback.blend.clear(); + if (end_notify) { + finished_anim = playback.assigned; + } return; } List::Element *> to_erase; @@ -306,6 +309,8 @@ bool AnimationPlayer::_blend_pre_process(double p_delta, int p_track_count, cons end_reached = false; end_notify = false; + finished_anim = StringName(); + bool started = playback.started; // The animation may be changed during process, so it is safer that the state is changed before process. if (playback.started) { playback.started = false; @@ -326,6 +331,10 @@ void AnimationPlayer::_blend_capture(double p_delta) { } void AnimationPlayer::_blend_post_process() { + if (!finished_anim.is_empty()) { + emit_signal(SceneStringName(animation_finished), finished_anim); + } + if (end_reached) { // If the method track changes current animation, the animation is not finished. if (tmp_from == playback.current.from->animation->get_instance_id()) { @@ -342,7 +351,6 @@ void AnimationPlayer::_blend_post_process() { playing = false; _set_process(false); if (end_notify) { - emit_signal(SceneStringName(animation_finished), playback.assigned); emit_signal(SNAME("current_animation_changed"), ""); if (movie_quit_on_finish && OS::get_singleton()->has_feature("movie")) { print_line(vformat("Movie Maker mode is enabled. Quitting on animation finish as requested by: %s", get_path())); diff --git a/scene/animation/animation_player.h b/scene/animation/animation_player.h index db3c39201e4..3e1fb059cff 100644 --- a/scene/animation/animation_player.h +++ b/scene/animation/animation_player.h @@ -52,6 +52,8 @@ public: private: AHashMap animation_next_set; // For auto advance. + StringName finished_anim; + float speed_scale = 1.0; double default_blend_time = 0.0;