How to check if animator is in transition?

I am using Animator.MatchTarget and getting the warning that “Calling Animator.MatchTarget while in transition does not have any effect.”

How do I check if I am in transition? This is an example line:

if (anim.GetCurrentAnimatorStateInfo(0).IsName("Base Layer.WalkFwdLoop"))
				anim.MatchTarget(targetPosition, targetRotation, AvatarTarget.Root, new MatchTargetWeightMask(, 1), 0.1f, .8f);

How do I ask Unity if the animation state is in transition?

Your if Statement should be: if (anim.GetCurrentAnimatorStateInfo(0).IsName("Base Layer.WalkFwdLoop")&&anim.GetCurrentAnimatorStateInfo(0).normalizedtime< 0.81f) //This would prevent match target being called after it exceeds the target matching time limits. Make sure the animation doesnt crossfades before the given normalied time
you can also add this block of statement below:

else if(anim.GetCurrentAnimatorStateInfo(0).IsName("WalkFwdLoop")&&anim.GetCurrentAnimatorStateInfo(0).normalizedtime > 0.81f && anim.isMatchingTarget)

May be there’s no need of checking transitions :slight_smile:

Use animator.IsInTransition()

Documents Link: Unity - Scripting API: Animator.IsInTransition

Also if you want to check a specific transition, select your transition in the animator, give it a name (shown in the Image bellow), then in your scripts check it like this:

if ( data.UnityAnimator.GetAnimatorTransitionInfo(0).IsUserName(“TransitionName”))`

or for performanse sake convert that string into a animator hash and store it somewhere (e.g. in your class) then check the hash like this:

int targetTransitionNameHash = Animator.StringToHash("TransitionName");
void Update()
       if( animator.GetAnimatorTransitionInfo(0).userNameHash == targetTransitionNameHash )