-
-
Notifications
You must be signed in to change notification settings - Fork 22k
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
StateMachine has delay which is caused by transition from Start to the first state needs one frame #91215
Comments
The end of the State is not delayed, but it seems that the start of the next State is delayed by processing one frame to transition from the Start state to the first state. I assume that we can eliminate this delay if the transition is not broken. The MRP in follow indicates that a total of 10 frames of animation progressing at 1 FPS, but if there are two layers in the StateMachine, it will take 12 frames to end. |
switch_mode: at_end
transition 2 frames lag
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
@Watersilver I sent #94304 so please check it out, as there should appear to be no longer a clear delay that we can visually notice. However, for some reason the numbers that MRP prints are the same as before. It might be worth taking a video, or slowing down the Process speed by setting a limit on FPS in ProjectSetting to see if there is a difference when comparing the two (before or after PR). If there is no difference there, probably MRP is including something in the if-conditions for printing that has nothing to do with visuals. And then, If there is no problem in practicality, I think this issue can be closed. |
I will check it out today and let you know |
Ok so I gave it a look and the issue seems to still be there. It's probably caused by something other than what you fixed. To be honest, I can't even see the delay in the MRP anymore. I had spent so much time looking at it when I opened the issue that it was easily apparent to me but now I can't really see it. I started wondering if I gaslit myself into believing it in the first place so I made a better MRP that compares a state machine animation with an animated sprite 2d animation and it can easily be seen that they become out of sync: The right side animation uses a state machine and the left one just an animated sprite 2d. I understand that there's no guarantee that they should give me the same result and I've already made bad assumptions about how the state machine works in the past. However there is something that makes me believe that they'd give me the same result if there was no issue. Again, like in the first MRP, I set the animation tree callback process mode to manual and I call Some new stuff I noticed with the side by side comparison:
To use the new MRP:
Also I checked the code that prints the numbers and I can't find a mistake. I think the numbers printed are correct but the delay is not easily noticable. Basically the code that prints them is an accumulator that increases every tick and becomes zero and prints the result when the animation changes. I've run it in both _physics_process and _process with the same results. I've moved away from animation trees for my project so I don't really care if you close the issue. The problem I can see with this kind of stuff is that there seems to be some uncertainty about how exactly the state machine runs animations and it's unfit for syncing with other animations. I would only use it for stuff where details aren't too important. If that's what the animation tree tool is supposed to be used for that's alright. If on the other hand it's meant to be used for detailed animations it should give consistent results no matter how many times Also, do we know what happens in the following scenario: We have one animation with 100 frames and a state machine with 50 animations of 2 frames which are ordered to transition at_end to the next until they reach the last. Does it stay in sync? If it doesn't then the animation tree is not a good tool to create and combine different animations because while in the original example the delay cannot be really seen, the error is systematic and it would add up after 50 transitions causing a clear delay. (I don't have time to check this right now, however I might make it depending on your reply.) |
Ah, I understand perfectly. The following project is a simple 9 second synchronization of 3 chained animations and 1 continuous animation, and I can confirm that the problem is still there after fix #94304. As I checked the StateMachine state, I think it comes from the fact that the 0th frame is being processed after the transition. This is the same problem as the recommendation to use advance(0) if you do not want to process the 0th frame when AnimationMixer playback started. We may need to add some option to AnimationNode to handle this in each Node. |
Alright, I sent #94372. As I wrote there, although there could still be problems depending on fps and animation length due to floating point precision errors, but it should solve the main problem of this issue, and I think we can close this issue. |
Tested versions
System information
Windows 10
Issue description
Animation in state machine that is configured to play only once and then transition to another animation lags for a few ticks on its final frame.
When I set callback_mode_process to manual and make multiple animation tree advance calls though lag gets reduced and starting at five times there is not lag at all.
Expected: When animation ends instantaneously move to next animation without lag.
Steps to reproduce
When you run the MRP the output prints the animation, its frame and how many ticks the frame lasted.
When you turn around until the run_turn animation transitions to the run animation you should see something like:
player run turn | frame: 7 | lasted: 6
This is the final frame of the player run turn animation and the correct non laggy version.Select the player character scene and change the anim_tree_advance_steps property to select how many times to call the animation tree
advance
method.If you set it to 1 the behavior is the same as if we didn't use the manual animation tree advance method and callback_mode_process was set to idle or physics.
now if you turn around again to transition from run_turn -> run you will probably feel the delay between the transition but if not you should see something like:
player run turn | frame: 7 | lasted: 8
= Two ticks of lag for the final frame of the player run turn animation.I get these results consistently. 6 for non laggy version 8 for laggy but it might be machine dependent.
Minimal reproduction project (MRP)
AnimTreeIssues.zip
The text was updated successfully, but these errors were encountered: