Search Unity

intentionally ignoring translation on humanoid/generic rig bones

Discussion in 'Animation' started by Dawdlebird, Jan 6, 2020.

  1. Dawdlebird

    Dawdlebird

    Joined:
    Apr 22, 2013
    Posts:
    88
    So usually people want to enable translate animation on humanoid bones; I want the opposite: To have translation animation be ignored (because it gets applied, which I don't want).

    I'm trying to reuse animation on a slightly different proportioned character, which depends on only rotational animation to be applied. I've already switched to humanoid avatars with the expectation that those are designed that way (although it would be nice if this was an option for generic rigs as well), but I find that for the jaw joint (one of the optional joints), translation still gets applied! Is there a way to prevent this? Is there a way in general to strip translation animation from a clip? Perhaps a way to use the an asset postprocessor for this?
    Any help would be appreciated!

    Edit: I've used a postprocessor script to strip every curve in every animation clip on import, so all that gets applied is some base pose the animator uses, and it is here that these translations seem to get applied! No idea how to prevent this though...
    Edit: Alright, seems the problem was I was borrowing animations from a character that had not been converted to humanoid... Problem solved for humanoid rigs, although ideally I'd like to be able to use generic rigs (those are lighter in terms of performance, right?), but is there any way to have translation animation be ignored on those? Just removing the curves doesn't cut it; some bindpose information still gets applied.
     
    Last edited: Jan 6, 2020
  2. Dawdlebird

    Dawdlebird

    Joined:
    Apr 22, 2013
    Posts:
    88
    And again I run into this problem with extra bones in humanoid rigs. Humanoid bones get stripped of their translation data, but extra bones are not. For example; animal tails seem to all adjust to the translation values of the source animations (even if these translation values are static) Anyone knows a clean way to strip these?
     
  3. Dawdlebird

    Dawdlebird

    Joined:
    Apr 22, 2013
    Posts:
    88
    So, ended up going the postprocessor route after all... Not ideal, but it works. Here is the code for my situation, if anyone is struggling with the same stuff. Notice that I check for the path containing "tail", since this applies to joints I've named "tail_something", but you'd obviously have to specify whatever joints you want to strip from positional animations.

    Code (CSharp):
    1.  
    2. using UnityEngine;
    3. using UnityEditor;
    4.  
    5.  
    6. public class AnimationTranslationStripper : AssetPostprocessor
    7. {
    8.  
    9.     void OnPostprocessAnimation(GameObject go, AnimationClip clip)
    10.     {
    11.         StripClip(clip);
    12.     }
    13.  
    14.     void StripClip(AnimationClip clip)
    15.     {
    16.         // get all curve bindings on clip
    17.         EditorCurveBinding[] bindings = AnimationUtility.GetCurveBindings(clip);
    18.  
    19.     // iterate through bindings
    20.         for (int i = 0; i < bindings.Length; i++)
    21.         {
    22.        
    23.             if(bindings[i].path.Contains("tail"))
    24.             {            
    25.                 if (bindings[i].propertyName.Contains("LocalPosition"))
    26.                 {
    27.                     AnimationUtility.SetEditorCurve(clip, bindings[i], null);
    28.                 }
    29.  
    30.             }
    31.         }
    32.  
    33.  
    34.     }
    35. }