title: How can get animations from the sub state machine?
body: <pre><code>using System.Collections;
  using System.Collections.Generic;
  using System.Linq;
  using UnityEngine;
  
  public static class IListExtensions
  {
      /// &lt;summary&gt;
      /// Shuffles the element order of the specified list.
      /// &lt;/summary&gt;
      public static void Shuffle&lt;T&gt;(this IList&lt;T&gt; ts)
      {
          var count = ts.Count;
          var last = count - 1;
          for (var i = 0; i &lt; last; ++i)
          {
              var r = UnityEngine.Random.Range(i, count);
              var tmp = ts[i];
              ts[i] = ts[r];
              ts[r] = tmp;
          }
      }
  }
  
  public class PlayAnimations : MonoBehaviour
  {
      private AnimationClip[] clips;
      private Animator animator;
  
      private void Awake()
      {
          // Get the animator component
          animator = GetComponent&lt;Animator&gt;();
  
          // Get all available clips
          clips = animator.runtimeAnimatorController.animationClips;
      }
  
      private void Start()
      {
          StartCoroutine(PlayRandomly());
      }
  
      private IEnumerator PlayRandomly()
      {
          var clipList = clips.ToList();
  
          while (true)
          {
              clipList.Shuffle();
  
              foreach (var randClip in clipList)
              {
                  animator.Play(randClip.name);
                  yield return new WaitForSeconds(randClip.length);
              }
          }
      }
  }
  </code></pre>
  
  <p>This will get all animations from the states in the regular top controller state machine. But I created a sub state machine name Magic StateMachine.</p>
  
  <p>And I want to get all the animation clips from the states only inside Magic StateMachine.</p>
  
  <p>Screenshot of the animator controller:</p>
  
  <p><a href="https://i.stack.imgur.com/qSFVg.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/qSFVg.jpg" alt="Animator Controller"></a></p>
  
  <p>And a screenshot of the sub state machine and the states I want to get the animation clips from and play randomly:</p>
  
  <p><a href="https://i.stack.imgur.com/jobvK.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/jobvK.jpg" alt="Sub state machine"></a></p>