- Home /
Is it safe to call Animator.Update() in OnStateEnter to force changes in that method to apply to the first displayed frame of the new state?
I have a state machine in the animation system. On one of my states, I want to set the normalizedTime of the animation after a transition, subject to certain conditions. Basically, I want to have control over the frame on which the animation starts.
To achieve this I call animator.Play(0,layerIndex,newNormalizedTime) in OnStateEnter. However, there will sometimes be a brief time (looks like a single frame, maybe two) in which the change I made in OnStateEnter doesn't show up, and the animation starts from the beginning. The effect is a flash in the model to the animation initial position before it goes to my assigned normalizedTime.
I have determined (basically by dumb luck) that if I call animator.update(0) in OnStateEnter, after I set the new normalized time, this little flash of the default animation start goes away. This implies to me that the animation system always displays the first frame of a new animation after OnStateEnter has been called, but doesn't necessarily apply changes from the animator controller before it displays this frame. If animator.update is applying those changes, it makes sense that this would solve my problem.
I'm hoping somebody with a better understanding of the animation system can explain to me what is actually going on, and whether this is a safe and robust way to do what I'm trying to do.
Your answer
Follow this Question
Related Questions
How to delete a StateMachineBehaviour via Editor Script? 1 Answer
State Machine Behaviours not executing when changing animators at runtime 0 Answers
how to make multiple transition from one state? 1 Answer
"Anim A -> Anim B, Anim C -> Anim B" or "Any State -> Anim B" would there be a difference? 0 Answers
StateMachineBehaviour.OnDestroy is getting called by SetActive 1 Answer