Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Animator not playing animations

Discussion in 'Animation' started by spitre, Feb 15, 2018.

  1. spitre

    spitre

    Joined:
    Feb 15, 2018
    Posts:
    3
    I'm new to unity trying to set up a simple UI that makes a wolf 3D character sit. I set up a two state animator controller which transitions from the idle animation to the sitting animation when a bool goes from false to true. Then I attached the animator and a script to a game object. I put a button in a canvas somewhere else in the project and set the on click behavior to run a function in the script that changes the bool from false to true. I know the bool is being changed because I set up print statements to tell me what its state is and when I run the game the first animation plays but the character does not transition into the sit animation. My code is
    public void animationfunction()
    {
    anim = GetComponent<Animator>();
    if (anim.GetBool("SitBool") == false)
    {
    Debug.Log("false");
    anim.SetBool("SitBool", true);
    }
    else
    {
    Debug.Log("true");
    anim.SetBool("SitBool", false);
    }
    }
    Can anyone help with this?
     
  2. StickyHoneybuns

    StickyHoneybuns

    Joined:
    Jan 16, 2018
    Posts:
    207
    You do not need to use debug.log with animation transitions. You can simply open up the animator of the object while the game is running and view the bool values being cycled in the parameters tab. You can also view the state in which your animation is in. I recommend looking at that to determine where your animation is hanging up.

    I think your code is wrong though. You are not giving the animation time to transition before you set the bool SitBool back to false. SitBool is true for exactly one frame and false every other frame unless holding down the button and if you have it scripted for holding down. This means by the time Unity checks for the transition the bool may already be false again. You need to take out the else statement and check to see if the transisiton actually happened then set it back to false.

    Use this to get the current state.

    https://docs.unity3d.com/ScriptReference/AnimatorStateInfo.IsName.html

    Then once you know you are in the sit state set SitBool back to false.

    Also when posting code use insert>code key on the toolbar. It makes it easier to read.
     
    anbleidd likes this.
  3. spitre

    spitre

    Joined:
    Feb 15, 2018
    Posts:
    3
    So I tried this
    Code (CSharp):
    1. public void animationfunction()
    2.     {
    3.         anim = GetComponent<Animator>();
    4.         anim.SetBool("SitBool", true);
    5.         if (anim.GetCurrentAnimatorStateInfo(0).IsName("Base.seat") == true)
    6.         {
    7.             anim.SetBool("SitBool", false);
    8.         }
    9.     }
    10. }
    Looking in the animator tab SitBool is turned to true when the button is pressed but the animation still doesn't play and SitBool is never turned to false. I guess this means either my code is incorrect(likely), for some reason setting sitBool to true doesn't transition the animator into the next state as it should, or both. Also, when SitBool is set to true, the animator displays the blue bar scrolling in the correct state indicating that its the playing the animation but the animation doesn't play. Any ideas?
     
  4. StickyHoneybuns

    StickyHoneybuns

    Joined:
    Jan 16, 2018
    Posts:
    207
    Take a screenshot of the animator controller playing with the blue bar you mentioned. If there is a blue bar then it is playing something, just maybe not what you think it is. Click on the animation state "sitting" in the animator controller and see what animation is in the Motion field in the inspector. It has to be that you have the wrong animation assigned to your animation state.

    https://docs.unity3d.com/Manual/class-State.html

    Also, have you looked at the preview window to see that your animation is in fact correct when you imported it?
     
  5. spitre

    spitre

    Joined:
    Feb 15, 2018
    Posts:
    3
    Sorry for the delay. The animation is correct, I checked the preview again. I've attached the screenshot of what it looks like when I hit play. It says its playing the animation I want when I want, that just isn't happening in the game
     

    Attached Files:

  6. StickyHoneybuns

    StickyHoneybuns

    Joined:
    Jan 16, 2018
    Posts:
    207
    I'm stumped at this point but lets break things down even more. Remove the transitions from the idle state and just add one entry transition to the sit state with no transition parameters. Do this and see if the animation goes immediately to the sit position on play. If it doesn't play then It will help determine what to do next. Go ahead and remove all scripts from that gameObject as well so we know that the scripts aren't overriding something.
     
  7. Super_Solomob422

    Super_Solomob422

    Joined:
    Jul 7, 2019
    Posts:
    7
    Same thing happens, to me. It works for the animation component but that won't loop it. And the animator component won't play the animation even thought the blue bar is there.
    .
     
  8. ThreeRing

    ThreeRing

    Joined:
    Aug 24, 2016
    Posts:
    15
    It has been a while since you post, but did you get a solution for this? I'm having the same issue and could use some tips!
     
  9. mattbohinski0806

    mattbohinski0806

    Joined:
    Oct 31, 2019
    Posts:
    1
    I am having the same problem, any solutions?
     
  10. Blenderik

    Blenderik

    Joined:
    May 14, 2013
    Posts:
    138
    If I only have one animation clip in my fbx it seems to play it, but as soon as there are more, the clip in the animator gets the blue progress bar, but it's not effecting the Model. It does in the preview (inspector inside the fbx)
     
  11. Kramboja

    Kramboja

    Joined:
    May 9, 2014
    Posts:
    1
    Same problem here, after doing a bit of research I figured out my problem is with the different layers I had in my animator. Where on one of my layers it said that my animation should've been playing, on another layer it was playing a different animation. after playing a bit around I fixed my problem. Hope to point anyone in the right directions for a solution! Have a nice christmas everybody! :)
     
    resh871 and grantdscs like this.
  12. tatoyarliyah

    tatoyarliyah

    Joined:
    Sep 8, 2019
    Posts:
    5
    if anyone is still interested, i managed to fix this by just unchecking apply root motion in my Animator. I don't understand how this worked but it did lol
     
  13. AudacityFilms

    AudacityFilms

    Joined:
    Jul 7, 2018
    Posts:
    6
    This might be a dumb fix but i figure all help no matter the size may help especially with the new comers, make sure you're freakin' item you wish to trigger the animation HAS A RIGIDBODY... smh rookie mistake on my part, but in my defense I haven't slept but 3 hours today :/ just glad i finally got it working.
     
    ARandomGuy96 likes this.
  14. FodderBott

    FodderBott

    Joined:
    Sep 27, 2020
    Posts:
    1
    I had the same issue where the animations seemed to play in the animator with a blue bar, but some of them didn't actually play. I resolved the problem by deleting the bad animations and re-adding them to the animator from scratch. All the settings were the same so I have no idea if anything changed or if it was just a bug.
     
  15. airsickword1287

    airsickword1287

    Joined:
    Feb 11, 2021
    Posts:
    1
    have similar issue, where it only plays one animation (the one thats set to be the default) however in the animator it shows that it should be switching to another animation but doesn't. this only happens when I set a condition, will continue to happen even when the condition is met.

    Edit: I fixed this by both replacing the animator component, and making the condition require conditions to be false rather than true
     
    Last edited: Feb 11, 2021
    MyReazon likes this.
  16. Beatrix69

    Beatrix69

    Joined:
    May 26, 2021
    Posts:
    1
    Hola. A mi también me pasa lo mismo y no se que hacer. Yo tengo la animación en un Player que tiene una animación con el movimiento y dentro tengo el arma con otra animación pero aunque parece que funciona la animación no la hace. ¿ Alguien me puede hechar una mano? gracias.
     
  17. sahirvirmani

    sahirvirmani

    Joined:
    Jan 19, 2017
    Posts:
    3
    Just in case anybody has this problem today... Make sure the objects that you're trying to animate are not set to static... :) I spent way too much time trying to solve this problem.
     
  18. Matheusnum1

    Matheusnum1

    Joined:
    Nov 20, 2021
    Posts:
    1
    I went in the transition, settings of that transition and unchecked the "Can Transition to Self" and it worked.
     
  19. Haape

    Haape

    Joined:
    Sep 12, 2015
    Posts:
    2
    Thanks so much !!!!!!
     
  20. alfredbaudisch

    alfredbaudisch

    Joined:
    Dec 13, 2010
    Posts:
    45
    Another one to add to the list here - make sure you activate the Animator component :D

    upload_2023-5-20_11-0-31.png
     
  21. ujz

    ujz

    Joined:
    Feb 17, 2020
    Posts:
    28
    FYI if you change the name of your limbs, the animation will not play even though Animator will show a blue progress line.
     
  22. keroltarr

    keroltarr

    Joined:
    Apr 4, 2021
    Posts:
    1
    I have one more reason this can happen. I had 2 animators set. 1 on the main object which I was using and another one was default set on the model (child of main object) which was overriding and not allowing my animator to take affect. I disabled the animator on the model and my animator now works.