Search Unity

Getting a reference to all Animation States in an Animator Override Controller?

Discussion in 'Animation' started by sketchygio, Mar 3, 2021.

  1. sketchygio

    sketchygio

    Joined:
    Nov 6, 2014
    Posts:
    31
    Is there any way to do this during runtime (or otherwise if that's not possible)?

    Basically I've been coding such that I've made my own FSM and, when the player attacks, the time between attacks for a weapon depends on which weapon is equipped, specifically on how long its 'Attack' state's animation clip lasts. Each equippable weapon comes with an animator override controller to overwrite the 'Attack' animation state. To limit the player's attacks, I'd like to be able to reference the generic 'Attack' state in a given override controller and get a reference to its animation clip length, which would act as the limiting factor.

    Getting a reference to the specific animation clips is easy enough, but every weapon will have clips with different names attached, which makes coding around that somewhat difficult.

    My only other solution would be to basically keep checking every frame until the Animator happens to bumble into 'Attack' state and THEN update the needed values based on that. But that just sounds... like a mess.

    Am I missing something obvious?

    Edit for grammar
     
  2. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    2,570
    Check out Animancer (link in my signature). It lets you avoid Animator Controllers and control everything in scripts. End Events make issues like this completely trivial and the Weapons example is probably pretty close to what you're trying to achieve.
     
  3. sketchygio

    sketchygio

    Joined:
    Nov 6, 2014
    Posts:
    31
    Thanks Kybernetik. I've actually already run into your other posts on other similar threads during my search for answers and have looked into Animancer, which seems pretty cool! May look into it in the future, seems like it can do exactly what I need and more.

    For the time being though, since I'm a masochist, I accidentally ran into the Playables API for Unity, which doesn't feel very well-documented online (as a code newbie at least, I've gone years without even ever hearing about it), but it seems to hold all the answers when it comes to controlling and playing animation clips at will, free from the clutches of the animator states.

    Does anyone know if Playables will receive some extra love in the form of some kind of more thorough documentation for dumb-dumbs like me or even some tutorial vids? Gonna try to learn what I can but, at my level of understanding, the available information surrounding Playables feels fairly obtuse and disorganized.

    Hopefully studying the PlayableGraph Visualizer will help that process..
     
  4. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    2,570
    Animancer is built on the Playables API and I posted this explanation about it a while ago.

    The Playables documentation is indeed terrible and you shouldn't expect it to get any better. They haven't even fixed any of the simple documentation issues I've submitted bug reports about.
     
    sketchygio likes this.
  5. sketchygio

    sketchygio

    Joined:
    Nov 6, 2014
    Posts:
    31
    Haha, I see! Well that would explain a lot.

    Well, thank you for going knee-deep into learning this stuff to be able to explain it to the rest of us, and thank you for trying to push for better documentation for the community at large. If the Unity team truly doesn't plan on further documenting Playables, that would truly be sad, as there is so much wasted potential there (and wasted man-hours because of it). But I have to hold on to hope as when I first started using Unity, nested prefabs wasn't even a thing, and it was (thankfully) properly implemented eventually. So if nothing else, hopefully some Unity dev sees this post, and can at least tally up my voice to yours to give this API the care it deserves.