Search Unity

Playing Animations without the Finite State Machine - Skills with Animations

Discussion in 'Animation' started by Stoicheia, Sep 14, 2021.

  1. Stoicheia

    Stoicheia

    Joined:
    Jun 25, 2020
    Posts:
    27
    I am making a game with a bunch of skills which carry AnimationClips as variables. I want to play the animation whenever the skills are activated. My skills and characters aren't really connected (for design purposes, any character can have any combination of skills), so I want a simple way to play animations without having to use the state machine. I obviously don't want to make a state in my state machine for every single skill!

    My current solution is to use "Animation" instead of "Animator". But here's my problems with this:

    1. Some say that "Animation" is a legacy feature, which makes me believe that there is a better solution using the finite state machine.

    2. I want to use the state machine for set actions like walking, idle etc. So I think that Animation and Animator have to coexist on the same gameobject.

    Is this approach good? Or is there a better way to do animations where characters can have an indefinite number of skills, each with their own associated animation(s)?

    Note: I had a look at animationoverrides, but it seems like you cannot add new states, only modify existing ones.
     
  2. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    2,570
    I can't tell you about the solution I'd actually recommend because advertising isn't allowed here.

    The Playables API makes it possible to play new animations dynamically at runtime and can also blend those separate animations with Animator Controllers, but you'd have to be prepared to invest significant time in figuring out how to use it and essentially building your own animation system on top of it.

    The Legacy Animation system is also a viable option. I don't particularly like the system, but it's better than Animator Controllers so if it does everything you need there's nothing wrong with using it.
     
    Stoicheia likes this.
  3. Stoicheia

    Stoicheia

    Joined:
    Jun 25, 2020
    Posts:
    27
    I've sort of solved my problem.

    I didn't understand animation overrides when I wrote this post. Now, I realised that you can put a "dummy state" in the finite state machine and swap animations in and out of that. So whenever I want to play the animation of a skill, I just put the animation of that skill into the dummy state and play it.