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

Replaced loops_current with end_loop in AnimationNodeStateMachinePlayback #60247

Merged
merged 1 commit into from
Apr 28, 2022

Conversation

ScottVMariotte
Copy link
Contributor

@ScottVMariotte ScottVMariotte commented Apr 14, 2022

First time committing to open source!

Fixes #59967

Found in AnimationNodeStateMachinePlayback

Private variable loops_current in was being used in the method _travel to calculate the end of a loop.

if (next_pos < pos_current) {
    loops_current++;
}
pos_current = next_pos; //looped
if (switch_mode == AnimationNodeStateMachineTransition::SWITCH_MODE_AT_END) {
    goto_next = next_xfade >= (len_current - pos_current) || loops_current > 0;

This created an issue when an Advance Condition (atEnd) was changed from false to true when loops_current > 0 (any time after the first loop). This caused an immediate transition instead of at the end of the animation loop.

Could not find any other use for loops_current so I replaced it with end_loop to solve this issue;

Relevent changes in _travel

{ //advance and loop check

	float next_pos = len_current - rem;

-	if (next_pos < pos_current) {
-		loops_current++;
-	}
+	end_loop = next_pos < pos_current;
	pos_current = next_pos; //looped
}


if (switch_mode == AnimationNodeStateMachineTransition::SWITCH_MODE_AT_END) {
-    goto_next = next_xfade >= (len_current - pos_current) || loops_current > 0;
-    if (loops_current > 0) {
+    goto_next = next_xfade >= (len_current - pos_current) || end_loop;
+    if (end_loop) {
......
}

First time contributing please inform me if I did anything out of conduct :)

@ScottVMariotte ScottVMariotte requested a review from a team as a code owner April 14, 2022 19:13
@ScottVMariotte ScottVMariotte changed the title Replaced 'loops_current' with 'end_loop' in AnimationNodeStateMachinePlayback Replaced loops_current with end_loop in AnimationNodeStateMachinePlayback Apr 14, 2022
@Calinou Calinou added bug cherrypick:3.x Considered for cherry-picking into a future 3.x release topic:animation cherrypick:3.4 labels Apr 14, 2022
@Calinou Calinou added this to the 4.0 milestone Apr 14, 2022
@ScottVMariotte ScottVMariotte requested a review from a team as a code owner April 14, 2022 20:32
@ScottVMariotte
Copy link
Contributor Author

ScottVMariotte commented Apr 14, 2022

Sorry did not mean to close this... I'm still trying to get used to using GitHub and was confused.... Sorry if I'm making a mess 😅

@KoBeWi KoBeWi removed the archived label Apr 14, 2022
@ScottVMariotte ScottVMariotte force-pushed the AnimationTree_atEndFix branch from 1bcae60 to ac426c0 Compare April 14, 2022 22:05
@ScottVMariotte ScottVMariotte force-pushed the AnimationTree_atEndFix branch from ac426c0 to c526ee6 Compare April 14, 2022 22:18
@akien-mga
Copy link
Member

The changes look good style wise, just needs a review from folks familiar with animation features (@godotengine/animation).

Copy link
Member

@SaracenOne SaracenOne left a comment

Choose a reason for hiding this comment

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

Took me a bit to understand the actual issue, but yep, as far as I can tell, seems fine to me, tested it, and it appears to fix the bug.

@akien-mga akien-mga merged commit 1eb0936 into godotengine:master Apr 28, 2022
@akien-mga
Copy link
Member

Thanks!

@akien-mga
Copy link
Member

Cherry-picked for 3.5.

@akien-mga akien-mga removed the cherrypick:3.x Considered for cherry-picking into a future 3.x release label May 5, 2022
@akien-mga
Copy link
Member

Cherry-picked for 3.4.5.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

AnimationTree switch mode atEnd ignored after the animation loops
6 participants