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 StateMachine transition Sync not working on looped animations #84586

Closed
wants to merge 3 commits into from
Closed
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
4 changes: 2 additions & 2 deletions scene/animation/animation_blend_tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ double AnimationNodeAnimation::_process(const AnimationMixer::PlaybackInfo p_pla
process_state->tree->call_deferred(SNAME("emit_signal"), "animation_started", animation);
}
// Finished.
if (prev_time < anim_size && cur_time >= anim_size) {
if (prev_time < anim_size && cur_time >= anim_size && !is_looping) {
process_state->tree->call_deferred(SNAME("emit_signal"), "animation_finished", animation);
}
}
Expand All @@ -178,7 +178,7 @@ double AnimationNodeAnimation::_process(const AnimationMixer::PlaybackInfo p_pla
}
set_parameter(time, cur_time);

return is_looping ? HUGE_LENGTH : anim_size - cur_time;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We explained in #82089 that this change is currently inacceptable. This revision is being worked on as godotengine/godot-proposals#8083.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be fair, I absolutelly agree animationtree/node needs reworking, this PR is basically a makedo with what I got.

It's worth mentioning though, kinda like SkeletonIK3D, while reworking is mandatory, we do need something to work with when possible, after reading the proposal I understand my PR may cause more trouble than benefits, but I do hope we get something to work with in the meantime while animationtree gets reworked

return anim_size - cur_time;
}

String AnimationNodeAnimation::get_caption() const {
Expand Down
12 changes: 11 additions & 1 deletion scene/animation/animation_node_state_machine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
#include "animation_node_state_machine.h"
#include "scene/main/window.h"

#include "scene/animation/animation_blend_tree.h"

/////////////////////////////////////////////////

void AnimationNodeStateMachineTransition::set_switch_mode(SwitchMode p_mode) {
Expand Down Expand Up @@ -1038,7 +1040,15 @@ bool AnimationNodeStateMachinePlayback::_can_transition_to_next(AnimationTree *p
return false;
}

if (current != p_state_machine->start_node && p_next.switch_mode == AnimationNodeStateMachineTransition::SWITCH_MODE_AT_END) {
// Prevent automatic transitioning looped animations
bool is_looping = false;
Ref<AnimationNodeAnimation> node = p_state_machine->states[current].node;
if (node.is_valid()) {
Ref<Animation> anim = p_tree->get_animation(node->get_animation());
is_looping = anim.is_valid() && anim->get_loop_mode() != Animation::LOOP_NONE;
}

if (current != p_state_machine->start_node && p_next.switch_mode == AnimationNodeStateMachineTransition::SWITCH_MODE_AT_END && !is_looping) {
return pos_current >= len_current - p_next.xfade;
}
return true;
Expand Down
Loading