Search Unity

Mecanim: Getting override controller's clip name that's currently playing

Discussion in 'Animation' started by pixpusher2, Aug 27, 2016.

  1. pixpusher2

    pixpusher2

    Joined:
    Oct 30, 2013
    Posts:
    121
    Hey there,

    So I've 2 characters, lets just call them Human and Cat. They both share the same Mecanim Animator Controller setup via Override Controllers.

    Now while they both share the same setup, I'd like the Cat to NOT play the "Talk" state when it's called. Is there a way to insert a NULL clip in the Cat's Override Controller for the "Talk" state, or a way to detect the overridden clip's name via script so that I can do some coding magic to ignore it when it's the Cat?

    I've also tried this script, but it returns "Talk" regardless of animation that overrides it.
    Code (CSharp):
    1. actor.animComponent.GetCurrentAnimatorStateInfo(0).shortNameHash
    I've spent hours Googling and have found nothing useful. I prefer not to add a boolean to all my characters to manually track this (I've got lots of characters and different states that needs ignoring). Legacy animation handles this nicely with a simple null check, but Mecanim is just not up for it.

    Any help will be great. Thanks!
     
  2. hakankaraduman

    hakankaraduman

    Joined:
    Aug 27, 2012
    Posts:
    354
    hi, this code you wrote returns state, not the clip as far as I know.

    I'm also new to using mecanim and having trouble to get the clip's name, speed and setting them. So confusing and there is no scripting manual for mecanim to do these kind of things. If I can access state, I can't access clip, vice versa. I hope someone points us to a good resource about this.
     
  3. pixpusher2

    pixpusher2

    Joined:
    Oct 30, 2013
    Posts:
    121
    Yea I wish the docs were a bit more fleshed out. There doesn't seem to be a way to access info of the playing clip as far as I've found. Wish they exposed more of Mecanim's functions through script.:(
     
  4. Mecanim-Dev

    Mecanim-Dev

    Joined:
    Nov 26, 2012
    Posts:
    1,675
    you could try to create a Talk clip for the cat that does nothing, simply create a empty clip
     
    pixpusher2 likes this.
  5. pixpusher2

    pixpusher2

    Joined:
    Oct 30, 2013
    Posts:
    121
    Thanks, Mecanim-Dev. I made a Talk clip for the Cat which starts and ends with frame 0 (essentially empty), but the Animator still plays it and the character just freezes for about a second. :eek:

    On the other hand, a Talk clip that starts at frame 0 and ends with 1 worked a little better. It is still played, but only for 1 frame, so it's baaaarely noticable except for the slight transition pop. I guess this is the best solution for now in the absence of a proper null/empty clip support.

    Cheers :)