Search Unity

Shared animator with many different possible ability animations

Discussion in 'Animation' started by Limnage, Nov 8, 2020.

  1. Limnage

    Limnage

    Joined:
    Sep 12, 2013
    Posts:
    41
    I'm trying to accomplish something that seems like it should be fairly simple:

    I have enemy units which are displayed with a 2D sprite. All of the enemy units currently share the same animator (if the enemy unit animations become more complicated later, then perhaps it may be better to make separate animators for different categories like humanoid).

    All enemy units have the same types of animations:
    • Idle
    • Move
    • Attack
    • Ability (many different abilities)

    Currently the idle, move, and attack animations are all simple scale/translation animations that are shared among all enemies, but eventually each enemy may have their own idle, attack, and move animation (probably not).

    I currently have it set up so that boolean parameters cause transitions between the idle, move, and attack states, which all only have one animation.

    The difficulty is with the ability animations. Each monster has different abilities, and I want to be able to specify in the ability data (scriptable object) which animation each ability should use. Currently I only have a handful of different ability animations (generic spell, generic ranged attack, etc), shared among all enemies, but in the future there will be more animations specific to types of enemies (like humanoid melee attack, etc.).

    What is the easiest and cleanest way to set up this type of logic in Animator?

    The braindead solution seems to be:

    make a separate state for every single ability animation along with a separate boolean parameter

    but this seems insane and unscaleable. The logic of transitioning into and out of the ability state is the same for each ability, it's just the actual animation that plays depends on that ability data, so it seems like there must be a better way.
     
  2. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    2,568
    The best way to do it with an Animator Controller is to use Animator Override Controllers.

    But you might also be interested in Animancer (link in my signature) which lets you avoid wasting time messing around with Animator Controllers and overrides and just control everything in scripts. The Basic Movement example only contains a single script, but since all the animation references are assigned in the Inspector you can just assign different animations for each character so the bottom of that page shows a bunch of other characters all being controlled by the same logic.
     
  3. Limnage

    Limnage

    Joined:
    Sep 12, 2013
    Posts:
    41
    Thanks, Animancer seems interesting (I'll check it out).