Search Unity

  1. We are migrating the Unity Forums to Unity Discussions by the end of July. Read our announcement for more information and let us know if you have any questions.
    Dismiss Notice
  2. Dismiss Notice

AnimationMode.StopAnimationMode() does not work

Discussion in 'Animation' started by sean244, Jun 9, 2021.

  1. sean244

    sean244

    Joined:
    Nov 4, 2017
    Posts:
    97
    This is my script:

    Code (CSharp):
    1. using System.Linq;
    2. using UnityEditor;
    3. using UnityEngine;
    4.  
    5. [ExecuteAlways]
    6. public class NewBehaviourScript : MonoBehaviour
    7. {
    8.     private void Awake()
    9.     {      
    10.         if (!Application.isPlaying)
    11.             PlayAnimation();
    12.     }
    13.  
    14.     private void PlayAnimation()
    15.     {
    16.         AnimationMode.StartAnimationMode();
    17.         AnimationMode.BeginSampling();
    18.         var animationClip = GetComponent<Animator>().runtimeAnimatorController.animationClips.First(x => x.name.Equals("clip"));
    19.         AnimationMode.SampleAnimationClip(gameObject, animationClip, 0);
    20.         AnimationMode.EndSampling();
    21.     }
    22. }
    23.  
    It plays an animation in edit mode exactly like I want it to. The only problem is that now the play button in the Animation window is grayed out.
    play button.jpg
    I think this is because AnimationMode.InAnimationMode is set to true. But I can't turn it off. The following code keeps printing to true:
    Code (CSharp):
    1. private void Update()
    2. {
    3.     AnimationMode.StopAnimationMode();
    4.     print(AnimationMode.InAnimationMode());
    5. }
    6.  
     
    Last edited: Jun 9, 2021
  2. Whatever560

    Whatever560

    Joined:
    Jan 5, 2016
    Posts:
    574
    Having the exact same issue after some tests the animation mode won't turn itself off
    It's always return true. Did you find how to turn it off ?
     
  3. sean244

    sean244

    Joined:
    Nov 4, 2017
    Posts:
    97
    Unfortunately not.
     
  4. Whatever560

    Whatever560

    Joined:
    Jan 5, 2016
    Posts:
    574
    I ended up avoiding manually setting the animation mode and rely only on timeline/animation window setting the state. At least it's not locking the state anymore for a minor inconvenience in our case.