Search Unity

Unable to trigger animations added to the ThirdPersonAnimatorController via script

Discussion in 'Animation' started by bettywhite, Jun 24, 2020.

  1. bettywhite

    bettywhite

    Joined:
    Oct 22, 2019
    Posts:
    14
    Howdy Animation Brains,

    I am trying to add additional animations (from Mixamo) to the ThirdPersonAnimatorController from the Standard Assets package and I am unable to trigger them with script, though I am able to trigger the animation by clicking the trigger in the Animator at runtime.

    For reference, here is the code I am using:
    Code (CSharp):
    1. private void Start()
    2. {
    3.       agent = GetComponent<NavMeshAgent>();
    4.       character = GetComponent<ThirdPersonCharacter>();
    5.       anim = GetComponent<Animator>();
    6.  
    7.       agent.updatePosition = true;
    8.       agent.updateRotation = false;
    9. }
    10.  
    11. void FaceCameraAndYawn()
    12. {
    13. if (Vector3.Distance(this.transform.position, cameraWaypoint2.transform.position) < 0.5f)
    14. {
    15.      character.Move(Vector3.zero, false, false);
    16.      anim.SetTrigger("Yawn");
    17.      //i have tried .Play as well (as shown below) with no success
    18.      //anim.Play("Yawn");
    19. }
    20. }
    Attached are screenshots of the arrangement I have in the Animator and the import settings I have used for the animation.
    Capture1.JPG

    Capture2.JPG

    Capture4.JPG

    Capture3.JPG

    Any advice would be hugely appreciated as I have exhausted just about every video and thread I could find on the subject matter to no avail.

    Thanks for reading. :)
     
  2. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    2,570
    One of the biggest problems with Animator Controllers is that there are so many bits and pieces in different places that it's hard to know what to include when asking for help. In this case, one of the first places to look to determine if SetTrigger("Yawn") does anything is the transition settings to make sure you have actually set it to use that parameter.

    But if Play("Yawn") also doesn't work, then the issue is likely something else. I can think of a few possibilities:
    1. Are both the model and animations the same Rig Type? (Humanoid)
    2. Can it play the Yawn animation if you just Right Click it and set that as the default state?
    3. Are you sure your script and Animator Controller are actually assigned to the right objects and you don't have another copy in your scene or something?
    4. Are you sure FaceCameraAndYawn is actually getting called by something?
    5. Does the trigger actually show as being activated if you inspect the object while it's running?
     
    bettywhite likes this.
  3. bettywhite

    bettywhite

    Joined:
    Oct 22, 2019
    Posts:
    14
    Oh my lawd, thank you for your response! My noob wheels are showing because as it turns out FaceCameraAndYawn was not getting called since it was getting stuck in a loop from a piece of code above it that I had omitted from my post. I can only laugh at the hours that were wasted!

    Again, I wish you a whole-hearted thank you for helping me with the debugging process. Have a wonderful day!