Restart Mecanim's Animator controller

Is there any way to Reset the Animator controller of an Avatar?
When a character dies, I would like to respawn it and restart its Animator controller (playing its default state and with all the parameters set with default values, just like when we Start a new game).

Ok, to finally answer this after all this time:

You must check if the Animator is initalised and if it is not manually invoke a “Rebind” which will re-initialise the Animator.


This is stated in the docs.

For Unity versions pre 4.5 use TonyLi’s answer.

As explained in the comments, Unity5.6 stores and restores the animator state on Animator disable/enable and game object deactivate/activate, so I suggest to apply @TonyLi’s answers 2 and 3 at the same time. If you only apply 2, the old animator parameters will be preserved and with only 3, the initial state may or may not be reverted depending on how your transitions are built.

I give implementation details below.

Step 1. Reset all animator parameters

You can use this method I wrote as an extension (it is based on [this answer][1] which aimed at restoring animator parameters):

/// Reset all animator parameters to their default
public static void ResetParameters (this Animator animator) {
	AnimatorControllerParameter[] parameters = animator.parameters;

	for (int i = 0; i < parameters.Length; i++) {
		AnimatorControllerParameter parameter = parameters*;*
  •   	switch (parameter.type)*
  •   	{*
  •   	case AnimatorControllerParameterType.Int:*
  •   		animator.SetInteger(, parameter.defaultInt);*
  •   		break;*
  •   	case AnimatorControllerParameterType.Float:*
  •   		animator.SetFloat(, parameter.defaultFloat);*
  •   		break;*
  •   	case AnimatorControllerParameterType.Bool:*
  •   		animator.SetBool(, parameter.defaultBool);*
  •   		break;*
  •   	}*
  •   }*
  • }*
    Step 2. Play from the initial state
    I suggest using a trigger with a standardized name (e.g. “Reset”) that you’ll use on all your animators that need to be reset.
    For each layer:
    - add a transition from Any State to your initial state on the condition of the Reset trigger
    - give that transition the highest priority among transitions from Any State
    - make it instantaneous (duration 0, no interruption)
    - check Can Transition To Self in case you want the animation to restart when the game object is already in its initial state.
    If you expect to reset your object during certain transitions, make sure those transitions allow Interruption from the Next State.
    You may also use [Animator.Play][2] (experimental) to play directly a state by name, but don’t forget to do this on all the layers.
    Final code
    Using the extension above:
    [1]: Parameters and States of Animator Reset on Object's Disable - Questions & Answers - Unity Discussions
    [2]: Unity - Scripting API: Animator.Play

I haven’t come across any way to do this easily. Here are some ideas:

  1. Destroy and re-instantiate the character from a prefab.
  2. Manually reset everything in your controller. For transitions, you could have a Boolean parameter named Reset that transitions from Any State to the starting state.
  3. Write a method to reset everything to the default values recorded in the AnimatorController. I describe how to get this information in this answer: Getting a list of mecanim states in Animator - Unity Answers