Animator.Play() Function question

Go to Animator.Play() Scripting API

public void Play(string stateName, int layer = -1, float normalizedTime = float.NegativeInfinity);

As you can see, we can move to specific point at Animator with Animator.Play() function.
My question is about how it works.

Check this image below.


[image 1]

‘A’ is state’s progress point.
‘B’ is point that has animation event.
‘C’ is point that I want to go to.

if I go to ‘C’ point by using Animator.Play(),


[image 2]

it’s not work like [image 2].


[image 3]

it’s work like [image 3].
why this function doesn’t go directly and go around? it cause ‘B’ point’s animation events.

if you know how to fix this problem, help me please.

There is two way to call this function

Animator.Play(Animator.StringToHash(“Animation”), -1, timeC);
or
Animator.Play(0, -1, timeC);

There is a difference between both call
the first one will create a transition from Animation to Animation.
And the second one will only change the current time of the current state.

Use the second one in your case

1 Like

Which version of unity are you using?

I just did a quick test and the first way is broken in 5.2.0f3 but fixed in 5.2.2f1.
the second way work in both version.

I’m using 5.2.0f3. maybe I should update to 5.2.2f1