Search Unity

Individual animated parts: Moving from legacy to Animator.

Discussion in 'Animation' started by Desprez, Oct 16, 2017.

  1. Desprez


    Aug 31, 2012
    I've got a lot of experience with scripting and C#, but I have a lot to learn about the Animator system in Unity.
    I've watched some tutorials and done some research, but so far nothing is addressing what I want to do or how to do it. I've spent many wasted hours watching tutorials only to find out half way through they aren't going address what I need. So I turn to you, mighty internet strangers.

    Instead of walking-running-breathing character animations (which, unfortunately, most tutorials are geared to) I have mechanical objects with individual moving parts, and animation clips for those isolated part movements. I mean, sure, I guess it would be nice to have the option of adding a "heavy breathing" override animation for my gun turret. You never know...

    I originally tried to tackle the problem by building a state machine that activates individual animation clips on individual parts with the legacy animation system. It works, but it's cumbersome and needs a lot of clean-up.

    So now, I'm trying to move to the Animator system, and since the animator component already is a state machine, it makes sense to use that, instead of re-inventing the wheel. It would certainly simplify my code.

    As a simple example, think of a pop-up gun turret. Say it has three states: Inactive, Ready, and Fire.
    For the transitions in and out of the Inactive state, I need a pop-up animation that moves the whole turret. And for the Fire state, I need a recoil animation for just the barrel.

    These animations are completely independent of each other and don't need to blend or override anything. However, they are related to specific states and it makes complete sense to control them from the same state machine. I'm running into problems trying to control the clips though.

    I can add clips the clips to the Animator, but there doesn't seem to be anyway to tell it that this clip only affects a specific part, and it instead applies the motion to the root part. Splitting them into multiple Animator components just seems silly, because then I'd still need a state machine to control the whole thing. (And besides, splitting them up across multiple animator components is going to cause tremendous workflow problems, and problems integrating with weapon control scripts. And this just gets worse in more complicated cases than the example I provided.)

    Various sources have led me to look at using animation layers to control individual parts. Well, at least it says it's for individual parts, but every example looks suspiciously like whole groups replacing other whole groups.

    This isn't what I want. And really seems like a little overkill for what I'm after.

    I have animations for specific parts that need to play at specific times. And it makes no sense to create a full object animation just to move a tiny little part far down in the object hierarchy. Not to mention the obvious problem of wanting to re-use a part on different objects with different hierarchies.

    Even as I type this, I'm seeing something that hints at having to re-create every animation clip from the perspective of the root object, and then only override that specific part. Seems rather inefficient. Is this what I have to do?

    What is the feature or workflow I'm looking for here?
    Last edited: Oct 16, 2017
  2. theANMATOR2b


    Jul 12, 2014
    I think you are correct in your assumption Desprez.
    The solution I used - which I admit my situation sounds far less complex than yours - was to combine all the separate mesh elements into one skin / rig.
    I know I know - that isnt a great solution because you will have to redo some rigging and animations - BUT - it will releave the headaches you are currently experiencing and allow you to avoid future headaches with the state machine setup.

    With all the animations in one rig and each animation played separately you will have a lot easier set up process because you can now think of the mechanical animations as if they were a common character - with separate animations.
    And you can use the layers how best they are used for - for overriding or additive animations, but certainly not required if all independent components animate separately - not at the same time, like a walking and shooting animation.