Why won't target matching work with this ledge climb up animation?

Hello!

I am trying to create the climb up part for my ledge climbing system using the MatchTarget function on the animator. Here is the code within my ledgeClimbing.cs script inside the Update() function:

if(stateManager.IsClimbingUp)
{
            GetComponent<Animator>().MatchTarget(aimPoint, transform.rotation, AvatarTarget.RightHand, new MatchTargetWeightMask(Vector3.one, 1.0f), 0.0f, 0.2f);
            Debug.Log("Matching target");
}

aimPoint is the point on the ledge above that the player should reach.

And this is the code inside the animation manager in the LateUpdate() function. I used LateUpdate so I could be sure that the climbUp trigger had been set (tells animator to perform climb up anim) before I set the MatchTarget in the next frame:

if(Input.GetKeyDown(KeyCode.Space) && stateManager.CanClimbUp)
 {
            anim.SetTrigger("ClimbUp");
            charControl.enabled = false;
            stateManager.IsClimbingUp = true;
            stateManager.IsClimbing = false;
            StartCoroutine(WaitForAnim(2.933f));
  }

The debug log indicates that the first if statement has been executed, so that is not the issue. I know this code will also execute it every frame, but I tried it just as soon as the space key is pressed but it didn’t do anything.

The animation plays as if I hadn’t called the MatchTarget function at all. Am I calling it in the wrong place?

The climb up animation has no root motion and is completely on the spot if that makes a difference.

Try waiting for the animator to say it’s in the correct state, instead of a single frame.
myAnimator.GetCurrentAnimatorStateInfo(0).IsName(“climbup”) returns a bool you can check.

  1. match target only available on BaseLayer
  2. when (animator.IsInTransition(0) == true) you CANNOT apply match target, warning will append in console
  3. just like @Radiago said you need to wait until GetCurrentAnimatorStateInfo(0).IsName(XXX)
  4. ensure the match target period are not overlap any other state, (2) happen and match target will cancel.