Search Unity

Solved oldWrappedTime > newWrappedTime

Discussion in 'Editor & General Support' started by TedBrown, Jan 31, 2012.

  1. TedBrown

    TedBrown

    Joined:
    Aug 6, 2011
    Posts:
    16
    Short answer: rewind the animation. Long answer:

    Ugh.

    OK, this is a multi-part problem that is (relatively) easy to solve, but stinks of Hack. You've been warned. :D

    =Background=
    I have five instances of a model with 70 animations. I am trying to use an AnimationEvent instead of manually tracking the passage of time, but of course I bumped up against the ridiculous notion that AnimationEvents can't be added to "read-only" animation assets.

    Not willing to dupe 70 animations (ugh), or write a script that would (at run time) do that for me (ugh!), I used my state machine's Enter state to manually add the event.

    =Problems=
    * It added the event each time I entered the state.
    * There is no way (at this time of writing) to check on, or remove, animationevents (UGH!)

    =Solution 0.5=
    Not being sure if the animation event was being added to ALL instances of the animation, or just the one for my gameobject, I created a singleton "AnimationManager" that would be queried before adding the event. That singleton has this function:

    Code (csharp):
    1.  
    2.     private List<string> animationEventNames;
    3.     public bool AnimationEventAdded (string animationEventName)
    4.     {
    5.         if (animationEventNames == null)
    6.         {
    7.             animationEventNames = new List<string>();
    8.         }
    9.  
    10.         foreach (string animationEvent in animationEventNames)
    11.         {
    12.             if (animationEvent == animationEventName)
    13.             {
    14.                 return true;
    15.             }
    16.         }
    17.  
    18.         animationEventNames.Add(animationEventName);
    19.         return false;
    20.     }
    21.  
    =Problems 0.5=
    This solved the immediate issue of adding the event multiple times, but the second time the animation was played, I got this error:

    Code (csharp):
    1.  
    2.     oldWrappedTime > newWrappedTime
    3.  
    Note: the animation was being played in WrapMode.Once. I don't know if the issue exists if the animation loops.

    =Solution 1.0=
    By rewinding the animation on the event's exit state, which itself was triggered when the animation was complete, I killed the bug.

    But somewhere, a delicate coding flower is wilting in black darkness. =)
     
    Last edited: Jan 31, 2012
  2. TedBrown

    TedBrown

    Joined:
    Aug 6, 2011
    Posts:
    16
    Turns out... well... I'm not sure exactly how this happened, but when I tested it, I didn't run into any problems.

    But when I closed and restarted Unity (because it had crashed), the "oldWrappedTime > newWrappedTime" returned, always on the second and later play of the animation.

    I tried rewinding the animation before it played, instead of after. I tried stopping the animation instead of rewinding it. No luck.

    Then I removed any rewinding or stopping of the animation. I started the game.

    I triggered the animation once, no error, as usual.
    I triggered the animation again. NO ERROR! WHAAAAAAT?
    I triggered the animation a third time. Got the error. ..... whaaaat?

    Restarted the game.
    I triggered the animation once. No error.
    I triggered the animation again. Got the error.

    So, that's rad.

    AnimationEvents.

    Ugh.
     
  3. Steviebops

    Steviebops

    Joined:
    Apr 9, 2013
    Posts:
    132
    Was this ever solved? Im having the same problem.
     
  4. Zyrrith

    Zyrrith

    Joined:
    Oct 28, 2013
    Posts:
    1
    The 'oldWrappedTime > newWrappedTime' error occured for me when I tried to play an animation in the Awake or Start function. It would only occur once after launching the Unity Editor and playing the game, probably due to the slightly increased load time that occurs when the game is played for the first time after the Unity Editor is launched.

    My fix:
    Turn the Start function into an IEnumerator like in the example below. Unity supports the Start function as IEnumerator by default so you don't need to tweak anything else.

    Code (csharp):
    1.  
    2. public IEnumerator Start()
    3. {
    4.     //Wait one frame.
    5.     yield return new WaitForEndOfFrame();
    6.    
    7.     //Play animations as usual.
    8. }
    9.