Blending states without making transitions in Animator

I need to start animation state at certain time and at certain coordinates. I use “Animator.Play()” function and it works good, but it has no blending with previous state. I could make the trigger or condition in Animator, but in this case I cannot control the time of animation start (e.g. normalizedTime).
How can I blend animations without Animator or how can I start transition between states with normalized time?

I can’t speak to the actual use of this functionality as I have never had a case for it. However, it would seem that Animator.Crossfade() should do what you are trying to accomplish.

2 Likes

Thanks for the answer! Animator.CrossFade works, but is there way to supress blending of root bone position?

If you do override method OnAnimatorMove in a MonoBehaviour you can take control of the root position as you wish.

or if you prefer to use statemachinebehaviour

1 Like

Sounds good, in method OnAnimatorMove() I can assign root position. However how can I get the required root position? I want to get it from animation which fade out.
SetTarget() call and following Update() call lead to OnAnimatorMove() - it is the vicious circle

The solution would be to use SetTarget but don’t call Update(), the engine will tick the animator which will compute the target position which then you can retrieve in the next OnAnimatorMove to override the root motion blending as you wish.

Should I have second animator for my character? Because animator.CrossFade and animator.Play cannot be executed simultaneously.
What if I have 30-40 characters?

I’m not sure what you are trying to achieve. can you give us more detail?

Ok, I’ll try to explain what I need step by step.
I had a character in AnimationState1 and I wanted to make transition it to AnimationState2. It’s important to note that I need precise coordinates of character in any time.
So I wrote code like this:

float normalizedTime = getNormalizedTimeForAnimation(AnimationState2);
animator.Play(AnimationState2, 0, normalizedTime);
animator.SetTarget(AvatarTarget.Root, normalizedTime);
animator.Update(0f);
character.position = animator.targetPosition;

It works good, but there is no smooth transition between AnimationState1 and AnimationState2.
So I used CrossFade() function instead Play() and one problem appeared:
I cannot get required root position for AnimationState2 during cross fading.

float normalizedTime = getNormalizedTimeForAnimation(AnimationState2);
animator.CrossFade(AnimationState2, transitionDuration, 0, normalizedTime);
animator.SetTarget(AvatarTarget.Root, normalizedTime);
animator.Update(0f);
character.position = animator.targetPosition;

This code doesn’t work. If I don’t use SetTarget() function, I won’t be sure about precise coordinates.