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. Dismiss Notice

No way to reset an animator.

Discussion in 'Animation' started by RussBartley2, Feb 10, 2021.

  1. RussBartley2

    RussBartley2

    Joined:
    May 4, 2017
    Posts:
    3
    I'm at my wits end.

    I have a GameObject with an animator & an animationcontroller that is pooled, & disabled most of the time.
    But when the player comes to an encounter I unpool the entity, & use it.
    It sucessfully plays with its animation controller & states, & after it dies it ends up with some of the death animation translations & rotations applied to its subnodes. (x rotation = 90 degrees)

    I then disable & put the entity back in the pool.

    I don't want to reinstantiate the Gameobject as it is way too inefficient. I have to pool these GameObjects

    When the player gets to the next encounter with the same type of entity, the same GameObject is enabled out of the pool & reused.
    But the translations & rotations from the previous death animation are still applied to the prefab instance. So the gameobject then starts to play its animations on top of the old death transform.

    I need to reset the death animation back to its default position.

    I have tried to no avail:
    - animator.keepAnimatorControllerStateOnDisable = false;
    - animator.enabled = false; animator.enabled = true
    - animator.enabled = false & true in a coroutine with a second delay to make sure the game has updated to see if it reset the transforms.
    - animator.Play("Base Layer.Spawn", 0, 0f);
    animator.playbackTime = 0f;
    animator.Update(0f);

    None of which resets these transforms.

    Surely a base feature of Mechanim would be to reset it bask to its entry state?
    Seems like an oversight to me.
     
    bennetpe and tuccci like this.
  2. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    2,486
    Check out Animancer (link in my signature) which doesn't have this problem (and has many other advantages).

    I don't even know why the behaviour is different because it's handled entirely by the Playables API which is used by both Animancer and Mecanim so the strange additive behaviour you get when re-enabling objects must be caused by something stupid in the Animator Controller system itself.
     
  3. bennetpe

    bennetpe

    Joined:
    Jul 23, 2019
    Posts:
    5
    I have the same problem, do you find any solution?