Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Question Long running animation stops

Discussion in 'Animation' started by BlakeSchreurs, Jan 10, 2023.

  1. BlakeSchreurs

    BlakeSchreurs

    Joined:
    Aug 10, 2016
    Posts:
    52
    Hey folks,

    I have an animated clock that I'm working on as time allows. In it, I have an animation of a dog walking around the clock. After a few days (usually a weekend) the dog stops animating. All the other code is fine. There are no animation transitions. The animator is extremely simple (I think it has only one state). Any thoughts on why the animation might stop after a few days?

    Thank you so much!
     
  2. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,345
    You probably get to a time where the internal time counter becomes too large to work with floating point numbers. If you try:

    Code (csharp):
    1.  
    2. [MenuItem("Temp/Test")]
    3. public static void Test() {
    4.     float oneFrame = 1f / 60f;
    5.  
    6.     float threeDays = 60f * 60f * 24f * 3f;
    7.  
    8.     Debug.Log(oneFrame);
    9.     Debug.Log(threeDays);
    10.     Debug.Log(threeDays + oneFrame);
    11. }
    12.  
    You'll see that the second and third values are the same.


    I don't know if this is a problem with a global timer for the Animator, or just for the state. If it's just the state, the fix is simple - transition to a different copy of the state and then back again every now and again. That should make no difference visually, but would reset the timer. If it's a global Animator problem, then you'll need to Stop and Start the animator completely.