From d5ac08b279252b8ad5f7378b2f36143a50ad2a18 Mon Sep 17 00:00:00 2001 From: "Silc Lizard (Tokage) Renew" <61938263+TokageItLab@users.noreply.github.com> Date: Sat, 7 Jun 2025 08:35:39 +0900 Subject: [PATCH] Fix AnimationPlayer finished state in the editor --- .../plugins/animation_player_editor_plugin.cpp | 16 +++++++++++++++- editor/plugins/animation_player_editor_plugin.h | 2 ++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/editor/plugins/animation_player_editor_plugin.cpp b/editor/plugins/animation_player_editor_plugin.cpp index 723bda483f5..549a70a365c 100644 --- a/editor/plugins/animation_player_editor_plugin.cpp +++ b/editor/plugins/animation_player_editor_plugin.cpp @@ -80,6 +80,7 @@ void AnimationPlayerEditor::_node_removed(Node *p_node) { void AnimationPlayerEditor::_notification(int p_what) { switch (p_what) { case NOTIFICATION_PROCESS: { + finishing = false; if (!player || is_dummy) { track_editor->show_inactive_player_warning(false); } else { @@ -1210,6 +1211,9 @@ void AnimationPlayerEditor::edit(AnimationMixer *p_node, AnimationPlayer *p_play if (player->is_connected(SNAME("animation_list_changed"), callable_mp(this, &AnimationPlayerEditor::_animation_libraries_updated))) { player->disconnect(SNAME("animation_list_changed"), callable_mp(this, &AnimationPlayerEditor::_animation_libraries_updated)); } + if (player->is_connected(SceneStringName(animation_finished), callable_mp(this, &AnimationPlayerEditor::_animation_finished))) { + player->disconnect(SceneStringName(animation_finished), callable_mp(this, &AnimationPlayerEditor::_animation_finished)); + } if (player->is_connected(SNAME("current_animation_changed"), callable_mp(this, &AnimationPlayerEditor::_current_animation_changed))) { player->disconnect(SNAME("current_animation_changed"), callable_mp(this, &AnimationPlayerEditor::_current_animation_changed)); } @@ -1237,6 +1241,9 @@ void AnimationPlayerEditor::edit(AnimationMixer *p_node, AnimationPlayer *p_play if (!player->is_connected(SNAME("animation_list_changed"), callable_mp(this, &AnimationPlayerEditor::_animation_libraries_updated))) { player->connect(SNAME("animation_list_changed"), callable_mp(this, &AnimationPlayerEditor::_animation_libraries_updated), CONNECT_DEFERRED); } + if (!player->is_connected(SceneStringName(animation_finished), callable_mp(this, &AnimationPlayerEditor::_animation_finished))) { + player->connect(SceneStringName(animation_finished), callable_mp(this, &AnimationPlayerEditor::_animation_finished)); + } if (!player->is_connected(SNAME("current_animation_changed"), callable_mp(this, &AnimationPlayerEditor::_current_animation_changed))) { player->connect(SNAME("current_animation_changed"), callable_mp(this, &AnimationPlayerEditor::_current_animation_changed)); } @@ -1428,9 +1435,16 @@ void AnimationPlayerEditor::_list_changed() { } } +void AnimationPlayerEditor::_animation_finished(const String &p_name) { + finishing = true; +} + void AnimationPlayerEditor::_current_animation_changed(const String &p_name) { if (is_visible_in_tree()) { - if (p_name.is_empty()) { + if (finishing) { + finishing = false; // Maybe redundant since it will be false in the AnimationPlayerEditor::_process(), but for safety. + return; + } else if (p_name.is_empty()) { // Means [stop]. frame->set_value(0); track_editor->set_anim_pos(0); diff --git a/editor/plugins/animation_player_editor_plugin.h b/editor/plugins/animation_player_editor_plugin.h index dfcc65ff3cd..944a9261c01 100644 --- a/editor/plugins/animation_player_editor_plugin.h +++ b/editor/plugins/animation_player_editor_plugin.h @@ -112,6 +112,7 @@ class AnimationPlayerEditor : public VBoxContainer { Ref reset_icon; Ref autoplay_reset_icon; + bool finishing = false; bool last_active = false; float timeline_position = 0; @@ -204,6 +205,7 @@ class AnimationPlayerEditor : public VBoxContainer { void _update_animation_blend(); void _list_changed(); + void _animation_finished(const String &p_name); void _current_animation_changed(const String &p_name); void _update_animation(); void _update_player();