Pause PlayableDirector but preserve extrapolations
I want to pause my PlayableDirector until a script completes a task (fetching data from a remote server).
To do this, I send a signal to this script and from this script I'm trying to pause the director and resume it after I get the data.
It works, but with a weird glitch I cannot solve - I can't find a method of pausing the director so that it will still apply extrapolation to animation clips. If I simply call director.Pause()
, the animated transform resets to how it was before the animation. I also tried setting timeUpdateMode to Manual and calling Evaluate in a coroutine with deltaTime = 0
, but that doesn't help either. I also tried calling the Evaluate with a very small delta time, like 0.001f * Time.deltaTime
, same effect.
I guess I can do a hack and just extend the extrapolated animation so that there's no extrapolation during the pause, but is there a better solution?
EDIT: actually, extending the clip didn't help. Looks like PlayableDirector doesn't apply its values at all when paused, which makes sense, but there should be a way to do this manually, like the Sample method on AnimationClip
Answer by LemonCurry · Mar 18, 2020 at 05:59 PM
So actually it wasn't the director's fault - I tried removing all states from the Animator and it fixed the issue. I guess the Animator was trying to go back to its default state when the director was paused?
Answer by seant_unity · Mar 19, 2020 at 11:51 AM
Director.Pause() will cause the director to stop updating the animation. So, if there is something else playing (like an animator controller), then that will take over. An alternative is to set the playback speed of the timeline to 0 using playable.playableGraph.GetRootPlayable(0).SetSpeed(0) to pause it, then reset the speed to 1 to resume it. That will keep the timeline playing, but not advancing.