A Unity ID allows you to buy and/or subscribe to Unity products and services, shop in the Asset Store and participate
in the Unity community.
Discussion in 'Animation' started by VoodooDetective, May 5, 2021.
How do I make legacy animations play in unscaled time?
Does the Legacy Animation component have a method like Animator.Update which lets you specify the delta time?
This is what I'm able to do currently, but it feels hacky and ?inefficient?
if (animator.isPlaying == false || string.IsNullOrEmpty(currentAnimation)) return;
AnimationState currentState = animator[currentAnimation];
currentState.time += Time.unscaledDeltaTime;
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.
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.
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?
If you just leave the animation playing it would stay at the values of the last frame so I'm not really sure what the issue is, but with Animancer you can make it stop doing anything by calling animancer.Playable.PauseGraph(); if you want to prevent it from wasting any performance re-applying the same values every frame.
Ah so I think I didn't communicate that clearly. I need the changes the animator makes to be persistent, even after the animation has stopped playing.
If I do this, main menu will disappear when I show the modal, but I don't want it to disappear.
If you play each animation on a separate Layer then they won't interfere with each other so you can have them all playing at once. I prefer to use a tweening system instead of animations for UI stuff because of issues like this so I'm not certain it will fix the problem, but it's worth trying.
Ahhh genius! Thanks so much for the suggestion. I feel much better not using my hack. Thank you!