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 display of progress bars on looped animations. #82089

Conversation

SaracenOne
Copy link
Member

@SaracenOne SaracenOne commented Sep 22, 2023

This PR changes the internal behaviour of the AnimationTree nodes 'time' parameters. Rather than storing the time for an individual animation, if the animation is looping, it stores the total cumulative time for every loop. This shouldn't cause precision issues since its a 64bit value. This is intended to future-proof for a new transition switch based on explicit time windows. This does not solve every aspect, I think we may want to refactor more polling of information into the nodes themselves, but this may prove a useful stopgap.

Narrowed scope, this PR simply now just introduces a workaround to display the progress bars in the state machine editor even if the animation is looping which was previous not possible due to internal changes which make it so that AnimationNodes no longer return the remaining time for a looped animation. It does this by introducing an alternative path where it attempts to look at the node, animation, and internal 'time' parameter directly.

Closes #81715

Copy link
Member

@TokageItLab TokageItLab left a comment

Choose a reason for hiding this comment

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

I tested this current PR and it seems that changing NodeAnimation causes loops random "despite Animation is not set looping" and a recurring bug that breaks the first frame when the State transitions.

incorrect looping state (click to detail)

Probably the fundamental cause of this random looping bug is that the state of is_looping information is not propagated to the AnimationStateMachine.

This was same before my refactoring. I remember that instead of being propagated the is_looping state, the looping was determined when the remaining time was decreasing (so the loop was broken when NodeAnimation playback mode is backward). After refactoring, looping is determined by HUGE_LENGTH (I remember doing this at the time of refactoring because there was no way to get the loop state semantically then).

Even if you make it return the correct RemainTime, it would be impossible to propagate the looping state unless you add an is_looping state to the argument.

We might come up with an implementation that adds an option to the StateMachine side to count loops independently of the AnimationNode, but it is impossible to count loops correctly since there is no semantic way to estimate the remaining time, so it should not be done.

Before:

Desktop.2023.09.22.-.17.35.14.09.mp4

After this PR:

Desktop.2023.09.22.-.17.35.14.10.mp4

Current AnimationTree API is also not semantic about estimating the remaining time, but it is stable by returning HUGE_LENGTH when information is missing to correctly estimate the time remaining.

I have written some of my opinions to RocketChat, so first, NodeAnimation should not be modified in the current stage. So first, we need to add a property to NodeSync to estimate what the remaining time is from for semantic transitions.

And I think the addition of this property should allow Nodes to have their own custom time, and allow Nodes downstream of NodeAnimation the possibility to override the upstream time remaining.

Then, finally we may need to do some parts of what this PR is trying to do ...or this PR could be a complete distraction. But for now, I warn you that it is very dangerous to rush to do this PR now.

If you want to solve #81715, what we can do at this stage is to implement loop_override, as I mentioned there.

And what could be improved in the GUI for now (because we don't have the way to estimate the semantic remain time of the animation that StateMachine's Node is processing), it would be to display HUGE_LENGTH (means remain time is unknown) to the user as an explicit symbol (but the PR for about that is not there yet).

@SaracenOne SaracenOne force-pushed the loop_animation_progress_display branch from 82ae5f1 to e19cf25 Compare September 23, 2023 01:34
@SaracenOne
Copy link
Member Author

Thanks again for looking at this. I do agree we probably need to investigate this issue more deeply and be somewhat of a quick-fix for what does seem like a deeper architectural problem. That being said, I do think this would be worth keeping around since cumulative time would allow for a more flexible transition system, but I agree about not rushing a change like this, hence why I'm keeping it in draft form. Either way, I have addressed some of the issues raised including non-looping animation looping (that was an oversight on my behalf). Still need to investigate first-frame breaking issue.

@SaracenOne SaracenOne force-pushed the loop_animation_progress_display branch from e19cf25 to e12933c Compare September 24, 2023 06:15
@SaracenOne
Copy link
Member Author

@TokageItLab I've looked more into the issues and I'm starting to understand them a bit better. While I think I fixed most of what was raised, I've decided that it makes sense to roll back the more risky architectural changes to the time value, and just limit it to the workaround which should re-enable the display of the progress bar on looping animations.

While I still think the change the time value makes sense for future architectural reasons, I've moved it to seperate branch and will revisit it with a more substantial proposal to back it up. I'm hoping this PR should be good enough for now. Modified the PR title to better reflect this and moved it out of draft status

@SaracenOne SaracenOne marked this pull request as ready for review September 24, 2023 06:16
@TokageItLab
Copy link
Member

TokageItLab commented Sep 24, 2023

Indeed, it is possible to retrieve the length of a NodeAnimation if it is limited to NodeAnimation, and it may be able to display that correctly as a GUI.

However, searching for the path in every frame when playing NodeAnimation is a performance killer and quite annoying. Although it's just the editor, so it won't be a problem at runtime.

These codes should will be unnecessary in the future if remain time can be retrieved semantically, but I am still doubtful that this workaround is necessary at this stage, and I am negative about this implementation. Even if we merge this at worst, we should leave a comment that these codes need to be removed at some point.

@SaracenOne
Copy link
Member Author

SaracenOne commented Sep 24, 2023

I agree this is a suboptimal approach, and figuring it out how to implement time tracking in a more holistic way would indeed be preferable. I consider this more of a backup plan just in case we can't decide on an optimal solution before release.

I'll look more into problem in the meantime.

@TokageItLab
Copy link
Member

TokageItLab commented Oct 12, 2023

Alright, I wrote the proposal godotengine/godot-proposals#8083. It will supersedes this PR.

@akien-mga
Copy link
Member

Superseded by #87171. Thanks for the contribution!

@akien-mga akien-mga closed this Mar 23, 2024
@AThousandShips AThousandShips removed this from the 4.x milestone Mar 24, 2024
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.

Looped animations can't transition automatically in state machine
5 participants