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 AnimationPlayer::play() process unwanted start between the same animations #82898

Merged
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
15 changes: 9 additions & 6 deletions scene/animation/animation_player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -415,28 +415,31 @@ void AnimationPlayer::play(const StringName &p_name, double p_custom_blend, floa
}

c.current.from = &animation_set[name];
c.current.speed_scale = p_custom_scale;

if (!end_reached) {
playback_queue.clear();
}

if (c.assigned != name) { // Reset.
c.current.pos = p_from_end ? c.current.from->animation->get_length() : 0;
c.assigned = name;
emit_signal(SNAME("current_animation_changed"), c.assigned);
} else {
if (p_from_end && c.current.pos == 0) {
// Animation reset but played backwards, set position to the end.
c.current.pos = c.current.from->animation->get_length();
} else if (!p_from_end && c.current.pos == c.current.from->animation->get_length()) {
// Animation resumed but already ended, set position to the beginning.
c.current.pos = 0;
} else if (playing) {
return;
}
}

c.current.speed_scale = p_custom_scale;
c.assigned = name;
emit_signal(SNAME("current_animation_changed"), c.assigned);
c.seeked = false;
c.started = true;

if (!end_reached) {
playback_queue.clear();
}
_set_process(true); // Always process when starting an animation.
playing = true;

Expand Down
Loading