Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix some animation state corruptions on activate and reset on save #86644

Merged
merged 1 commit into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion editor/editor_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -1739,7 +1740,14 @@ int EditorNode::_save_external_resources() {
static void _reset_animation_mixers(Node *p_node, List<Pair<AnimationMixer *, Ref<AnimatedValuesBackup>>> *r_anim_backups) {
for (int i = 0; i < p_node->get_child_count(); i++) {
AnimationMixer *mixer = Object::cast_to<AnimationMixer>(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<AnimationTree>(p_node->get_child(i));
if (tree) {
AnimationPlayer *player = Object::cast_to<AnimationPlayer>(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<AnimatedValuesBackup> backup = mixer->apply_reset();
if (backup.is_valid()) {
Pair<AnimationMixer *, Ref<AnimatedValuesBackup>> pair;
Expand Down
1 change: 1 addition & 0 deletions editor/plugins/animation_player_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 7 additions & 1 deletion scene/animation/animation_mixer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1974,7 +1974,13 @@ void AnimationMixer::_build_backup_track_cache() {
TrackCacheValue *t = static_cast<TrackCacheValue *>(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: {
Expand Down
7 changes: 4 additions & 3 deletions scene/animation/animation_tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Loading