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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice
  4. Dismiss Notice

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,487
    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).