Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question [SOLVED] Animations Only Playing After Enabling the Animator in the Editor

Discussion in 'Animation' started by ironfiftynine, Feb 8, 2023.

  1. ironfiftynine

    ironfiftynine

    Joined:
    Jan 22, 2013
    Posts:
    71
    Good day. I have implemented a system wherein a pet model is assembled through script. One of the child objects is the animator with an assigned Animator Controller. I'm having a problem playing the animation at the start of the game. The animator is in the right animation state but the animation clip is not playing. However, if I disable and then enable the Animator component in the Editor, the animations will play as expected. Please see my recorded run below:



    As you can see, I also tried enabling the animator component via script but it didn't work as well. Any suggestions on how to fix this? Thank you very much.
     
  2. ironfiftynine

    ironfiftynine

    Joined:
    Jan 22, 2013
    Posts:
    71
    I figured out a workaround for this problem. I refreshed the animator using Rebind and Update after the model has been assembled.

    Code (CSharp):
    1. this.petAnimator.Rebind();
    2. this.petAnimator.Update(0f);
     
    ShahenM and AAAAAAAAAE like this.
  3. nzzpoddiff376

    nzzpoddiff376

    Joined:
    Aug 16, 2017
    Posts:
    1
    I had this exact same issue. Tried the workaround and it worked perfectly!
     
    ironfiftynine likes this.
  4. UziLullaby

    UziLullaby

    Joined:
    Jul 4, 2014
    Posts:
    6
    I had this exact issue and the Rebind + Update(0f) trick solved this issue. Thank you so much ironfiftynine.

    Is this a Unity bug?
     
  5. ironfiftynine

    ironfiftynine

    Joined:
    Jan 22, 2013
    Posts:
    71
    I think it has something to do with how the animator works. I'm not sure how your models and rigs are structured but in my case, given that I updated the child objects and rigs of my character at runtime, I need a way to update the references of the animator as needed and my posted solution does that.
     
    UziLullaby likes this.