Skip to content

Commit 578d7cd

Browse files
committed
Ensure the AnimationPlayer emits animation_finished for every animation
1 parent bfa330d commit 578d7cd

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

scene/animation/animation_player.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,9 @@ void AnimationPlayer::_blend_playback_data(double p_delta, bool p_started) {
277277
// Finally, if not end the animation, do blending.
278278
if (end_reached) {
279279
playback.blend.clear();
280+
if (end_notify) {
281+
finished_anim = playback.assigned;
282+
}
280283
return;
281284
}
282285
List<List<Blend>::Element *> to_erase;
@@ -306,6 +309,8 @@ bool AnimationPlayer::_blend_pre_process(double p_delta, int p_track_count, cons
306309
end_reached = false;
307310
end_notify = false;
308311

312+
finished_anim = StringName();
313+
309314
bool started = playback.started; // The animation may be changed during process, so it is safer that the state is changed before process.
310315
if (playback.started) {
311316
playback.started = false;
@@ -326,6 +331,10 @@ void AnimationPlayer::_blend_capture(double p_delta) {
326331
}
327332

328333
void AnimationPlayer::_blend_post_process() {
334+
if (!finished_anim.is_empty()) {
335+
emit_signal(SceneStringName(animation_finished), finished_anim);
336+
}
337+
329338
if (end_reached) {
330339
// If the method track changes current animation, the animation is not finished.
331340
if (tmp_from == playback.current.from->animation->get_instance_id()) {
@@ -342,7 +351,6 @@ void AnimationPlayer::_blend_post_process() {
342351
playing = false;
343352
_set_process(false);
344353
if (end_notify) {
345-
emit_signal(SceneStringName(animation_finished), playback.assigned);
346354
emit_signal(SNAME("current_animation_changed"), "");
347355
if (movie_quit_on_finish && OS::get_singleton()->has_feature("movie")) {
348356
print_line(vformat("Movie Maker mode is enabled. Quitting on animation finish as requested by: %s", get_path()));

scene/animation/animation_player.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ class AnimationPlayer : public AnimationMixer {
5252
private:
5353
AHashMap<StringName, StringName> animation_next_set; // For auto advance.
5454

55+
StringName finished_anim;
56+
5557
float speed_scale = 1.0;
5658
double default_blend_time = 0.0;
5759

0 commit comments

Comments
 (0)