Search Unity

  1. Looking for a job or to hire someone for a project? Check out the re-opened job forums.
    Dismiss Notice
  2. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Legacy Animation - Unscaled time?

Discussion in 'Animation' started by VoodooDetective, May 5, 2021 at 3:05 AM.

  1. VoodooDetective

    VoodooDetective

    Joined:
    Oct 11, 2019
    Posts:
    150
    How do I make legacy animations play in unscaled time?
     
  2. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    1,514
    Does the Legacy Animation component have a method like Animator.Update which lets you specify the delta time?
     
  3. VoodooDetective

    VoodooDetective

    Joined:
    Oct 11, 2019
    Posts:
    150
    This is what I'm able to do currently, but it feels hacky and ?inefficient?

    Code (CSharp):
    1.         void Update()
    2.         {
    3.             if (animator.isPlaying == false || string.IsNullOrEmpty(currentAnimation)) return;
    4.             AnimationState currentState = animator[currentAnimation];
    5.             currentState.time += Time.unscaledDeltaTime;
    6.             animator.Sample();
    7.         }

    I thought for sure I was missing something. Also, I'm not entirely sure how this works. I assume it respects the frame-rate of the animation, but I'm not 1000000% positive.
     
  4. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    1,514
    Yeah, that looks rather hacky but I can't see a better way to do it.

    Why are you using the legacy animation system though? If it's just to avoid Animator Controllers, you might be interested in Animancer (link in my signature) which can be set to use unscaled time without needing any code.
     
  5. VoodooDetective

    VoodooDetective

    Joined:
    Oct 11, 2019
    Posts:
    150
    I actually did buy and love Animancer! The problem is I need the values set by the animator to be retained after the animation completes, and I haven't found a way to make that happen with Animator or Animancer.

    With Animator, even if I set "don't write defaults," the animator ignores if I set an object inactive on the last frame.

    Do you know anyway to make any of the three options work?
     
unityunity