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
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    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.