Version: Unity 6.3 Beta (6000.3)
LanguageEnglish
  • C#

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Parameters

Parameter Description
resetParameters Set to true to also reset the controller parameters to their default values. When set to false, only the controller state is reset.

Description

Resets the AnimatorController to its default state.

Use this method to reset the layers in the AnimatorController to their default state.

using System;
using UnityEngine;
using UnityEngine.Animations;
using UnityEngine.Playables;

// Press the Spacebar in Play Mode to reset the AnimatorController to the default state
[RequireComponent(typeof(Animator))]
public class AnimatorControllerPlayableResetExample : MonoBehaviour
{
    // The AnimatorController to be used with the Animator component.
    public RuntimeAnimatorController m_Controller;

    Animator m_Animator;
    AnimatorControllerPlayable m_ControllerPlayable;

    void Start()
    {
        m_Animator = GetComponent<Animator>();

        // Set up the PlayableGraph and AnimatorControllerPlayable and play the graph.
        var graph = PlayableGraph.Create(nameof(AnimatorControllerPlayableResetExample));
        m_ControllerPlayable = AnimatorControllerPlayable.Create(graph, m_Controller);
        var output = AnimationPlayableOutput.Create(graph, nameof(AnimatorControllerPlayableResetExample), m_Animator);
        output.SetSourcePlayable(m_ControllerPlayable);
        graph.Play();
    }

    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Space))
        {
            //This will reset the AnimatorController to the default state.
            m_ControllerPlayable.ResetControllerState();
        }
    }

    void OnDestroy()
    {
        // Destroy the PlayableGraph when the GameObject is destroyed.
        m_ControllerPlayable.GetGraph().Destroy();
    }
}