Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Animator clip count c# ?

Discussion in 'Animation' started by nbfp, Mar 1, 2019.

  1. nbfp

    nbfp

    Joined:
    Jul 30, 2015
    Posts:
    23
    I have characters that play random animations when interacted with. This works fine. However in my script I have harcoded:

    int nextClip = Random.Range(1,7)


    I would like to get the number of animationclips in an Animator (Different characters have varying number of clips), so that my script could be more usable without worrying about that clipcount number (7 in my example code).
     
  2. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    2,485
    Unfortunately, it's not possible to get that kind of information about the contents of an AnimatorController at runtime.

    However, this would be extremely easy to do with my Animancer plugin (link in my signature below). Instead of using an AnimatorController, it would let you give your script an array of AnimationClips, then you can just pick a random array element using Random.Range(0, array.Length) and tell it to play that clip.
     
    nbfp likes this.
  3. nbfp

    nbfp

    Joined:
    Jul 30, 2015
    Posts:
    23
    Thank You. Will not waste any more time trying to get this figured out. However, I am just a semi beginner and trying to avoid using assets made by others in order to learn the basics (Yes, I know, reinventing the wheel).