I have an animator with a single animation in its animatorController
I want to be able to tell it “go at time X and apply the state you’d have at that time”
Here’s how I try to do this currently:
// Get the playableGraph of the Animator, and make it so that we have to manually update it
PlayableGraph PlayableGraph = Animator.playableGraph;
PlayableGraph.Stop();
PlayableGraph.SetTimeUpdateMode(DirectorUpdateMode.Manual);
// Get the AnimationClipPlayable of the animation
// (I get it in a less ugly way in my real code. I promise!)
_clipPlayable = PlayableGraph.GetRootPlayable(0)
.GetInput(0)
.GetInput(0)
.GetInput(0)
.GetInput(0);
// Set the time of the clip to some arbitrary time we'd want to sample
_clipPlayable.SetTime(15.875);
Debug.Log(_clipPlayable.GetTime()); // This outputs 15.875
// Evaluate, so that the pose at that time should be applied
PlayableGraph.Evaluate();
Debug.Log(_clipPlayable.GetTime()); // This outputs 0
However, this doesn’t work. The animated object remains at its initial position.
What I’ve found is that if I try to Debug.Log(_clipPlayable.GetTime()) just before doing Evaluate(), the value is correct. But after Evaluate(), the “_clipPlayable.GetTime()” is back to 0.
I’ve been having a few issues with calling Evaluate(0f) (Which is synonymous with the default .Evaluate() ) on a playablegraph. If I do it even once, it seemingly refuses to be evaluated again. If I’m careful to not update it without a significant delta (and never negative deltas sadly ) I can keep it alive, but what it considers “zero” is seemingly a bit bigger than float.Epsilon.
I think the issue has to do with using the playableGraph on the animator, which has an animator controller playable that is also managing the time of the clips in the graph.
I’m having a similar problem; only I am using an “AnimatorControllerPlayable” directly in a PlayableGraph. I have found that if you drive “PlayableGraph.Evaluate” with a non-zero delta time then it won’t reset the time, but that seems like a little bit of a hack.
I even tried “SetPropagateSetTime” (discussed here ), but that doesn’t seem to fix the problem either.
It’s been about a year with no real solution. I would like to know the proper way to manually drive a PlayableGraph that contains an “AnimatorControllerPlayable.”
Is there any way we can get a more technical answer to this question?
What are you trying to accomplish? To me, this seems like expected behaviour, but I don’t have full context of what you are trying to do.
The animator controller resets the time of it’s clips when necessary (e.g. when a new state starts). Evaluate(dt) advances the current state. The controller doesn’t maintain the current time of all it’s clips, so changing their time while the graph is running would have an effect, but could always get reset if a transition occurs.
I think I have a similar request to the original question.
Old Animation clips had this nice function: clip.SampleAnimation(SomeObject, 15.48f); which would set the state of the object to exactly that timestamp.
It’d be great to have a playableDirector.SampleTimeline(4f); or, if that would be too much for the whole graph, perhaps per track we could sample the track at some time?
does exactly that for timeline. It does it by setting the time on the root node (the timeline playable), which configures the graph and all times of connected graphs based on that time.
For other playable graphs it very much depends on the structure of the graph. Each node has it’s own time, the graph itself doesn’t have a global time by default.