From 772a7539605bb5b0d3a15266faabf5d6b3daddc3 Mon Sep 17 00:00:00 2001 From: "Silc Lizard (Tokage) Renew" <61938263+TokageItLab@users.noreply.github.com> Date: Sun, 31 Dec 2023 01:20:44 +0900 Subject: [PATCH] Fix some animation state corruptions on activate and reset on save --- editor/editor_node.cpp | 10 +++++++++- editor/plugins/animation_player_editor_plugin.cpp | 1 + scene/animation/animation_mixer.cpp | 8 +++++++- scene/animation/animation_tree.cpp | 7 ++++--- 4 files changed, 21 insertions(+), 5 deletions(-) diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index 86925af4b47..c0d48609da3 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -47,6 +47,7 @@ #include "editor/editor_string_names.h" #include "main/main.h" #include "scene/3d/bone_attachment_3d.h" +#include "scene/animation/animation_tree.h" #include "scene/gui/color_picker.h" #include "scene/gui/dialogs.h" #include "scene/gui/file_dialog.h" @@ -1739,7 +1740,14 @@ int EditorNode::_save_external_resources() { static void _reset_animation_mixers(Node *p_node, List>> *r_anim_backups) { for (int i = 0; i < p_node->get_child_count(); i++) { AnimationMixer *mixer = Object::cast_to(p_node->get_child(i)); - if (mixer && mixer->is_reset_on_save_enabled() && mixer->can_apply_reset()) { + if (mixer && mixer->is_active() && mixer->is_reset_on_save_enabled() && mixer->can_apply_reset()) { + AnimationTree *tree = Object::cast_to(p_node->get_child(i)); + if (tree) { + AnimationPlayer *player = Object::cast_to(tree->get_node_or_null(tree->get_animation_player())); + if (player && player->is_active() && player->is_reset_on_save_enabled() && player->can_apply_reset()) { + continue; // Avoid to process reset/restore many times. + } + } Ref backup = mixer->apply_reset(); if (backup.is_valid()) { Pair> pair; diff --git a/editor/plugins/animation_player_editor_plugin.cpp b/editor/plugins/animation_player_editor_plugin.cpp index 7bb701cc7af..4b2fa1876dc 100644 --- a/editor/plugins/animation_player_editor_plugin.cpp +++ b/editor/plugins/animation_player_editor_plugin.cpp @@ -2157,6 +2157,7 @@ void AnimationPlayerEditorPlugin::_update_dummy_player(AnimationMixer *p_mixer) Node *parent = p_mixer->get_parent(); ERR_FAIL_NULL(parent); dummy_player = memnew(AnimationPlayer); + dummy_player->set_active(false); // Inactive as default, it will be activated if the AnimationPlayerEditor visibility is changed. parent->add_child(dummy_player); } player = dummy_player; diff --git a/scene/animation/animation_mixer.cpp b/scene/animation/animation_mixer.cpp index 6a320d52c5b..706d2100649 100644 --- a/scene/animation/animation_mixer.cpp +++ b/scene/animation/animation_mixer.cpp @@ -1974,7 +1974,13 @@ void AnimationMixer::_build_backup_track_cache() { TrackCacheValue *t = static_cast(track); Object *t_obj = ObjectDB::get_instance(t->object_id); if (t_obj) { - t->value = t_obj->get_indexed(t->subpath); + t->value = Animation::cast_to_blendwise(t_obj->get_indexed(t->subpath)); + } + t->use_discrete = false; + if (t->init_value.is_array()) { + t->element_size = MAX(t->element_size.operator int(), (t->value.operator Array()).size()); + } else if (t->init_value.is_string()) { + t->element_size = (real_t)(t->value.operator Array()).size(); } } break; case Animation::TYPE_AUDIO: { diff --git a/scene/animation/animation_tree.cpp b/scene/animation/animation_tree.cpp index 844b6e64e83..2b7c47c8695 100644 --- a/scene/animation/animation_tree.cpp +++ b/scene/animation/animation_tree.cpp @@ -568,10 +568,11 @@ bool AnimationTree::_blend_pre_process(double p_delta, int p_track_count, const pi.seeked = true; root_animation_node->_pre_process(&process_state, pi, false); started = false; + } else { + pi.seeked = false; + pi.time = p_delta; + root_animation_node->_pre_process(&process_state, pi, false); } - pi.seeked = false; - pi.time = p_delta; - root_animation_node->_pre_process(&process_state, pi, false); } if (!process_state.valid) {