Search Unity

  1. Looking for a job or to hire someone for a project? Check out the re-opened job forums.
    Dismiss Notice
  2. Unity 2020 LTS & Unity 2021.1 have been released.
    Dismiss Notice
  3. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

No way to reset an animator.

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

  1. RussBartley2


    May 4, 2017
    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;

    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.
  2. Kybernetik


    Jan 3, 2013
    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.