• RuntimesUnity
  • Issue with Spine animation becoming gradually slower after long play sessions

We're making a game for a game cabinet that could potentially be left running for weeks without being reset, e.g., in game arcades or showrooms. During testing, we found that the Spine animation's playback speed gradually becomes slower and slower over the course of a week.

The Spine animation is set up in Unity with only one animation playing (an idle loop). There is no code calling the game object. We tried generating a Mecanim Animator (Unity Animator) for the Spine object, but the issue persisted.

Currently, I'm still investigating how to best resolve this. I'm just wondering if anyone has come across a similar issue.

    Related Discussions
    ...

    It sounds like you are experiencing a gradual performance degradation issue with your Spine animations in Unity over extended periods. Here are a few steps and considerations that might help you diagnose and resolve the issue:

    1. Profiling: Use Unity's Profiler to monitor memory usage and CPU performance over time. This can help identify if there are memory leaks or other performance bottlenecks that accumulate over long play sessions.

    2. Garbage Collection: Check if there are any garbage collection issues. Frequent or inefficient garbage collection can cause performance degradation over time.

    3. Animation Cleanup: Ensure that Animation Cleanup is disabled when exporting your skeleton. This prevents keys identical to the setup pose from being removed, which might cause issues when layering animations.

    4. Draw Calls and Skeleton Complexity: Evaluate the complexity of your skeletons and the number of draw calls. High complexity and numerous draw calls can lead to performance issues. Refer to the Metrics - Spine User Guide: Performance for optimization tips.

    5. Update and LateUpdate: Check if most of the time is spent in Update or LateUpdate of SkeletonAnimation. Profiling these methods can help identify if they are causing the slowdown.

    6. Minimal Project: If possible, create a minimal Unity project that replicates the issue. This can help isolate the problem and make it easier to diagnose.

    7. Unity Version: Ensure you are using the latest version of Unity and the Spine-Unity runtime. Sometimes, updates can include performance improvements and bug fixes.

    8. Memory Leaks: Investigate if there are any memory leaks in your project. Memory leaks can cause performance degradation over time as the available memory decreases.

    If these steps do not resolve the issue, you might consider sending a minimal Unity project that demonstrates the problem to Esoteric Software for further assistance.

    I believe the solution is to use Skeleton Mechanim component instead of Skeleton Animation. I still need to test this, but right now I think this is the way to go.

    Thanks, you may close the post.

    @DOLeeNam I'm not sure the Skeleton Mechanim component will solve the issue. What you describe sounds like a floating point precision issue in relation to some fields/variables storing accumulative time.

    Can you give us more details, i.e. any code you use to animate the skeleton, whether you update the animation state and skeleton manually, or let the standard Spine component handle it for you automatically.

    DOLeeNam During testing, we found that the Spine animation's playback speed gradually becomes slower and slower over the course of a week.

    By "slower and slower", do you mean performance-wise, that the FPS are getting lower and lower over time? Or do you mean that animations actually play back slower, or differently in any way while the framerate is still high? Or are you using Physics Constraints and is it changing in physics behaviour?

    I believe the solution is to use Skeleton Mechanim component instead of Skeleton Animation. I still need to test this, but right now I think this is the way to go.

    SkeletonMecanim applies animations differently, so depending on what your actual problem is, this might change your situation for the better if it's just due to accumulated time at AnimationState being very high and losing precision. Performance-wise it should not make any difference. If it does, please don't hesitate to let us know.

      Harald

      The animation playback becomes slower while the rest of the game and the game FPS remains constant. There were no physics elements in our project.

      The floating point precision issue could absolute be a reason for the slow down. If there is a way to reset the Spine component or reset the Spine playtime back to 0, please let me know.

      I'm not 100% sure but the reason I mentioned SkeletonMecanim could be the solution is that we mistakenly had some Spine elements set up differently using SkeletonMecanim instead of SkeletonAnimation and those elements didn't get slowed down.

        DOLeeNam The floating point precision issue could absolute be a reason for the slow down. If there is a way to reset the Spine component or reset the Spine playtime back to 0, please let me know.

        If you have only a single animation playing, you could reset trackEntry.TrackTime, which is otherwise ever-increasing:

        using Spine;
        using Spine.Unity;
        using UnityEngine;
        
        public class ResetAnimationTime : MonoBehaviour {
        	void Start () {
        		var skeletonAnimation = this.GetComponent<SkeletonAnimation>();
        		skeletonAnimation.AnimationState.Complete += ResetTrackTime; // this is called upon each loop completion
        	}
        	void ResetTrackTime (TrackEntry trackEntry) {
        		float duration = trackEntry.AnimationEnd - trackEntry.AnimationStart;
        		trackEntry.TrackTime = trackEntry.TrackTime % duration;
        	}
        }

        Note that this will register to the Complete event of any animation at any animation track. If you need to reset some animations but not others, you can register to a single added animation via trackEntry.Complete += YourCallbackMethod.