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

To detect the end of the state machine, one frame is required after moving to the End state #94280

Closed
jerbrisebois opened this issue Jul 12, 2024 · 3 comments · Fixed by #94304

Comments

@jerbrisebois
Copy link

jerbrisebois commented Jul 12, 2024

Tested versions

  • Reproducible in 4.3-dev6_mono_win64 and v4.3.beta3.mono.official [82cedc8]

System information

Godot v4.3.beta3.mono - Windows 10.0.19045 - Vulkan (Forward+) - dedicated NVIDIA GeForce RTX 2080 (NVIDIA; 32.0.15.5612) - AMD Ryzen 7 3700X 8-Core Processor (16 Threads)

Issue description

When animations in an AnimationTree are fired with a OneShot node with the "shot" being the output of a StateMachine the "End" state causes a frame of another animation to be played prior to returning to the "in" animation. This can be somewhat mitigated by not transitioning the StateMachine to the "End" state but then the OneShot stays "Active" and can cause issues elsewhere.

2024-07-12.14-08-51.mp4

Expected behavior is that there is no "twitch" to another animation when firing animations this way.

Steps to reproduce

Create an asset with 3 animations. I used a character from Blender with

  • "default" - t-pose, single frame
  • "idle" - hands to the sides, relaxed, single frame
  • "wave" - 16 frame animation of the character raising the right arm then lowering it

In a scene containing the asset, add an AnimationTree. Use AnimationNodeBlendTree as the tree root. Link it to the AnimationPlayer on the asset and ensure it's set to Active.

In the AnimationTree add 3 nodes

  • Animation - set this to the idle animation
  • OneShot - feed the previous Idle animation into the "In" socket and feed the output to the "Output" node
  • StateMachine - Create a state machine.

In the state machine, add an animation state with the action to be performed (in my case, "Wave"). From "Start" to "Wave" create a transition. Immediate switch, Auto mode, Note: In my video example above I used a "Wave" variable condition but removed it for these steps as it is not needed to reproduce.

From "Wave" to "End" add a transition. "At End" switch, Auto mode.

Back out to the Root of the AnimationTree. In the OneShot node, use the dropdown to fire the animation. The action animation will play, then it will play one frame of the "default" animation then return to the "idle" animation. The "default" animation is not even explicitly used yet it still somehow gets triggered.

Minimal reproduction project (MRP)

animtwitchtest.zip

@jerbrisebois
Copy link
Author

Realized I didn't mention this but this occurs in game as well as in the editor. Just easier to reproduce in the editor.

@TokageItLab
Copy link
Member

TokageItLab commented Jul 13, 2024

This problem is not actually caused by the StateMachine performing a Reset at End, but rather by the StateMachine not performing a Reset (and don't apply any animation) at End. StateMachine has a Reset Ends option to control this. The default is false, so that the Reset process is not performed.

In the end, the reason for this is that the end of the StateMachine is determined "after" the End is reached, since there is nothing to play when the End is reached, so the Deterministic option is used to apply Reset when "there is nothing to play". Setting the Deterministic option to false solves this problem, but it causes another problem.

So, we may need to make the StateMachine end decision one frame earlier. Perhaps the correct fix is to start calculating the remaining time when _find_next detects that the next state is the End state. Related: #91215

For now, a workaround which may be a hack, but you can handle it by setting a very small fading duration (like 0.01) for the Transition to Ends.

@TokageItLab TokageItLab added this to the 4.x milestone Jul 13, 2024
@TokageItLab TokageItLab changed the title Animation Tree's OneShot animations from a StateMachine cause a "twitch" to occur at the end of playback To detect the end of the state machine, one frame is required after moving the End state Jul 13, 2024
@TokageItLab TokageItLab changed the title To detect the end of the state machine, one frame is required after moving the End state To detect the end of the state machine, one frame is required after moving to the End state Jul 13, 2024
@TokageItLab TokageItLab modified the milestones: 4.x, 4.3 Jul 13, 2024
@jerbrisebois
Copy link
Author

@TokageItLab You rock. I love this community.

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

Successfully merging a pull request may close this issue.

3 participants