Search Unity

Retargeting prop animation on humanoid rigs in mecanim.

Discussion in 'Animation' started by neginfinity, Jul 15, 2015.

  1. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    13,565
    I have character ("Char1") with a sword and animation. Sword is attached to "prop" bone, (Root->Hip->Spine->Spine1->RightShoulder->RightArm->RightForearm->RightHand->RightHandProp) and that prop bone is animated.

    I have ANOTHER character (say, "Char2"), also with sword, differently sized skeleton and similar hierarchy and I want to use existing animation on this character.

    The thing is... when I simply mark both skeletons as "humanoid" and reuse animation from "Char1" on "Char2", sword prop bone on "Char2" does not animate and keeps default position/rotation.

    How do I fix that? I need sword to animate on Char2, and I can't find much information about mecanim prop retargeting, and there's no "prop" slot in mecanim avatar configuration.

    I already tried renaiming hand bones to match names from original skeleton, that doesn't work. Now what?
     
  2. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    13,565
    So, nobody knows? It is supposed to be basic stuff. You know, like getting sword/gun animation transfer from one skeleton to another.
     
  3. theANMATOR2b

    theANMATOR2b

    Joined:
    Jul 12, 2014
    Posts:
    7,790
    The name of the bones have to be the same and the rigs have to be generic. I think? I haven't done this, but a mecanim guru confirmed it on another thread.
     
  4. Mecanim-Dev

    Mecanim-Dev

    Joined:
    Nov 26, 2012
    Posts:
    1,675
    As long as the bone name match you should be able to retarget the prop animation, this is true for humanoid and generic rig.
    For a humanoid rig, all extra transform are not imported by default, you must expand the mask from the model importer and make sure that your prop is also checked to import his animation.
     
    petey and theANMATOR2b like this.
  5. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    13,565
    Sigh.

    After reading this comment and wasting a hour or two I finally figured it out.

    First, in animation package I used "RightHandProp"/"LeftHandProp" weren't marked for import. Not sure why transformation were still applied to original model, though. However, marking those for import didn't fix the issue.

    The important part is... apparently, in case of props and floating bones mecanim checks their absolute path in hierarchy.
    Meaning, it searches for a bone named "Root/Hips/Spine/Spine1/RightShoulder/RightArm/RightForeArm/RightHand/RightHandProp" and animates it if it is found.
    However, when you make model in blender, create armature for it with "root" bone and export, you'll get extra node for the model. Meaning it will be "metarig/Root/Hips/Spine/Spine1/RightShoulder/RightArm/RightForeArm/RightHand/RightHandProp".
    If "path" doesn't match, bone doesn't get animated.
    So I nuked "root" bone, renamed "metarig" object to "Root" and exported it. That fixed the issue.
    I believe that because *.anim files are stored in text format I also could duplicate them and modify paths in text editor to match my target model.

    The funny thing is only sword animation package used absolute path for bones within its animation.
    I checked simple animation I made myself, and its *.anim file used this format:

    attribute: LeftHand.Thumb.1 Stretched
    path:

    instead of:

    path: Root/Hips/Spine/Spine1/RightShoulder/RightArm/RightForeArm/RightHand/RightHandProp

    -------

    Would be nice if you guys did something about it. It would've been way more convenient if instead of absolute path bones were identified by their parent, or relative path based on nearest accessible "humanoid" bone. With current setup it looks like I either have to shoehorn all the models into same skeleton topology+names or I'll need to tweak animations by hand and make copies for different characters. Neither of those are convenient option....
     
    FellowPlayer123 likes this.
  6. Mecanim-Dev

    Mecanim-Dev

    Joined:
    Nov 26, 2012
    Posts:
    1,675
    For the first implementation we were using only a relative path, this is working great for simple case but as soon as your scene grow you begin to have some name conflict when you aggregate more complex game object hierarchy together. You end up with many animator in the same hierarchy and this is when the relative naming scheme break. Managing those conflict from code is complex and error prone and there is some case that cannot be resolve.
     
  7. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    13,565
    While it is understandable, it would be nice to have some kind of control there. Name mapping or something.

    In my case I've been applying 3dsmax-created prop animation to blender model. Those have different naming schemes. Blender typically uses "forearm.L", "forearm.R", and 3dsmax bipeds use "LeftForeArm", "RightForeArm". While retargetable humanoid animations can deal with that, as soon as there are props, there's trouble, becase names do not match.

    I would prefer if instead of using full bone names, like "Root/Hips/Spine/Spine1/RightShoulder/RightArm/RightForeArm/RightHand/RightHandProp"
    Prop bones could refer to humanoid bones. Meaning something like
    "<Mecanim:Root>/<Mecanim:Hips>/....../<Mecanim:RightHand>/RightHandProp"
    Still full path, but much more flexible, because it does not lock me into using original naming scheme.
     
  8. Mecanim-Dev

    Mecanim-Dev

    Joined:
    Nov 26, 2012
    Posts:
    1,675
    This solution only work for rig without any extra bone, as soon as you have a transform between to human transform it doesn't work anymore.

    The real solution is add support for generic retargeting, this is a new feature we are working on to allow you to define your own rig, it would allow you to add new transform mapping like props and mecanim will remap the animation fro you.
     
    theANMATOR2b and hopeful like this.
  9. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    13,565
    However, in case of prop bones there's no reason to check skeleton beyond closest humanoid bone parent.
    If something is attached to "humanoid hand" in original skeleton, as long as it is attached to "humanoid hand" in new skeleton, it is probably what user wanted.

    Any ETA for that feature?
     
  10. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    13,565
    Does anyone have functional workaround for this issue? I keep bumping into this problem and I can't really wait for that "new feature" in mecanim forever.

    Problem.

    1. Original animation clip+model contains animation for a "prop" bone that is parented to Hand. rig is humanoid.
    2. New model has different hierarchy, and contains either differently named "prop" bone parented to differently-named "hand" OR game object that is not a part of model's avatar but is parented to (differently-named) "Hand"..

    Desired solution:
    Transfer animated local position and rotation from "prop" bone on original model/clip onto new bone OR gameobject.

    Any way to do that right now?
     
  11. theANMATOR2b

    theANMATOR2b

    Joined:
    Jul 12, 2014
    Posts:
    7,790
    (necro post / franken-post )
    Hey @neginfinity - did you find a workable solution to the problems you were having?

    Without knowing more specifics about your setup, there are a couple thoughts I have, but can't say for sure if any one will work.

    What exactly are your attempting to create with this? A character holding an animated gun? A character interacting with a bow and arrow? As long as the prop is a inorganic animated object - I think this could be accomplished a couple ways - to overcome the process of exporting the prop with the character rig and encountering the issues listed above.

    Have you considered animating the prop in Unity and parenting it to a game object that is then parented to the hand?
    Or simply exporting the animated prop separately - and exporting the character rig alone - then in Unity parent the animated prop to the hand? Is animation lost/wrong in this process?
    Seems like this would solve the problem of having to import the animated prop in with the rig which is causing issues.

    Have you considered creating a avatar mask for the character - that masks the animated prop, which then would allow for retargeting of the character while retaining the animations for the prop?
     
  12. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    13,565
    Nope. As far as I can tell, there isn't one.

    Also, I'm not really looking for solution at the moment. If you wanna chat about the subject (in case someone bumps into the same issue), I could do that.

    Originally it was related to character holding a sword. Basically, imagine knife spinning animation. Or spinning revolver around your finger. Simply parenting object to hand is not gonna cut it, because movement will be too restricted. If the data comes from mocap, then prop bone will have its separate movement, and removing that will make animation too stiff.

    The sword bone is part of character rig.
    Exporting separate sword animation is not what I would do, because in that case you'd need to babysit multiple controllers at once, which is a recipe for trouble and animations desynchronizing.

    That doesn't help.

    In the case of mecanim animation of non-humanoid bones (such as that prop bone) will ONLY transfer if resulting bone chains has completely identical names and topology. I.e. if source skeleton has Root->Hip->Spine1->Spine2->RClavicle->Rshoulder->RArm->RHand->RWeaponProp, and target has root->hip->spine1->spine2->spine3->clavicle.r->upperarm.r->lowerarm.r->hand.r->weaponprop.r, animation won't transfer. That kind of thing would happen if you're transferring animation from max-based character to maya or blender-based characters. Masks don't solve that kind of thing. Also, floating bones that are not parented to root will lose positional animation.

    It would be great if there was some way to just read/receive local transform from original animation clip, that would allow to implement "procedural" controller for the bone, similar to how IK works, but as far as I can tell, there's no real way to do it.

    So in case of unity, the "solution" is to ignore both mecanim and animation retargeting, and create unique set of animations for every character. So, basically, forget that animation retargeting exists. Which is very disappointinng.

    Unreal 4, on other hand, includes "prop" bones into default skeleton.

    IIRC unity has planned features for that somewhere on the roadmap, but as far as I can tell, date for their completion is "when hell freezes over".

    P.S. Why the sudden interest in the thread, though?
     
    Last edited: Feb 11, 2016
    rubble1 and theANMATOR2b like this.
  13. theANMATOR2b

    theANMATOR2b

    Joined:
    Jul 12, 2014
    Posts:
    7,790
    I was attempting to solve what I thought was a similar issue, though as I read through your thread it became obvious to me it was unrelated.
    And I wanted to know if you solved it since there was no resolution posted.

    Those damn prop bones are the problem. I think we might get a first taste of what is coming down the road when 5.4 is released. Fingers crossed.
     
  14. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    13,565
    As far as I can tell the only real "solution" is to forget that retargeting exists and use generic animations.

    Also, I wouldn't bet on a better mechanism being available 5.4.

    Either way, time will tell.
     
  15. 00christian00

    00christian00

    Joined:
    Jul 22, 2012
    Posts:
    1,035
    Why would you retarget a placeholder?
    It's just a simple offset from the hand. You can do it manually on the LateUpdate with something like:
    Code (CSharp):
    1.  
    2. WeaponTransform.position = HandTransform.TransformPoint(weaponLocalOffset);
    3.  
    That's all.
    Mecanim is truly a beast and can do already tons of things if you know your way.
     
    theANMATOR2b likes this.
  16. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    13,565
    It is not.

    The offset is animated. And to do that manually, you need to read that animation from original clip.

    Mocap data with props will contain separate animation track for the prop.

    Please read the actual question before replying, I've tried to make damn sure the information can't be misinterpreted.
     
    Last edited: Feb 13, 2016
  17. 00christian00

    00christian00

    Joined:
    Jul 22, 2012
    Posts:
    1,035
    My bad, you are right didn't read properly. Sorry.
     
    neginfinity likes this.
  18. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    13,565
    Sure thing, no problem.
     
  19. olavra

    olavra

    Joined:
    Jul 8, 2012
    Posts:
    2
    Hi guys

    I actually have the same exact problem as neginfinity has been describing. I was able to translate the animation by renaming the how rigging exactly the same as the original animation, but the RightHandProp inherits the transformation of the RightHand, applying both a the same time...
    Has anybody found a solution for this??

    Using generic animations doesnt work for me, I tend to have several problems with external rigs maching the ones done with Blender.
     
  20. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    13,565
    There's no real solution. If at some point you need weapon to detach from hand and fly in air, then you'll need additional prop bones - one that is parented to hand, and one that iparented to root and can float. During animation events, hide/show objects attached to those bones, meaning the moment your character throws weapon up, hide weapon in hand, and show floating weapon.

    However, because mechanim does not retarget weapon bones, and will not be able to retarget floating bone, transition won't be smooth. You COULD maybe introduce an offset transform between animated floated bone and the weapon (i.e. [floating weapon bone]->[offset]->[weapon object]) and at the moment weapon detaches calculated offset between recorded and actual naimation position and add compensation for the movement into "offset" bone, but this definitely won't be perfect.
     
  21. olavra

    olavra

    Joined:
    Jul 8, 2012
    Posts:
    2
    Meaning... I wasted my money buy an animation package that I cant use... amazing...
    Thanks neginifinity
     
  22. manutoo

    manutoo

    Joined:
    Jul 13, 2010
    Posts:
    522
    @Mecanim-Dev ,
    we're nearly 5 years later, and this issue is still in Unity (2019.4.1 here)... :(

    I have my animations with a custom bone for the racket and now I have a new tennis player with a different naming convention for the bone structures, and it seems I can't apply my old animations on it without some dirty trick, right ?

    There are only 2 solutions I can think of :
    - rename all the bones in the original file (which I can't do by myself)
    - create the legacy bone hierarchy so the legacy racket bone will get animated, then copy the result to the new racket bone in LateUpdate()

    Or am I missing something ?
     
  23. manutoo

    manutoo

    Joined:
    Jul 13, 2010
    Posts:
    522
    Little head-up for people running into that issue : if your prop's parent axis don't match (eg: hand x-axis was toward the fingers for your animations, but toward the thumb for your model), you'll also have to correctly rotate your transform.localRotation and redistribute (x, y, z) on transform.localPosition for the animation to work.

    As it's not something that can be done in 2 minutes, and is likely pretty though for newbies, while being a common situation met in video games, this should really be handled natively by Mecanim : that's the meaning of Unity. :confused:
     
  24. dibdab

    dibdab

    Joined:
    Jul 5, 2011
    Posts:
    976
    can't be it done parenting to hand bone and handling two animators? probably need to separate prop animation, right? (or using legacy duplicate as was mentioned)

    The offset is animated.

    yeah, that is tough.
    mi would try recording curves of generic, and play those back.
     
  25. Ed_Muel

    Ed_Muel

    Joined:
    Mar 16, 2017
    Posts:
    51
    Hi, same problem here, I can't see how more people don't... I've just bought a load of animations and models and now discovered they don't match because of the prop missing from humanoid retargets.

    I don't mind if there's a workaround, but now I'm really hesitant to buy anything else off the asset store because i can't tell if it will match or not.

    Early on in this thread one of the devs said:

    As long as the bone name match you should be able to retarget the prop animation, this is true for humanoid and generic rig.
    For a humanoid rig, all extra transform are not imported by default, you must expand the mask from the model importer and make sure that your prop is also checked to import his animation.

    Is this true, I've not been able to get unity to see any of the props for animating. What steps would you have to take to get this working? I've tried the below, where am I going wrong?

    Added a bone to the model in blender called rightHandProp

    Exposed it in unity

    Opened them .anim file and changed the absolute path to match the new bone.

    Thanks
     
  26. Ed_Muel

    Ed_Muel

    Joined:
    Mar 16, 2017
    Posts:
    51
    Just in case anyone finds this, i got it to work importing in to blender, then renaming all the bones leading up to the prop bone to match the animation rig.

    I tried to just chanfe the path in the text file as mentioned above but couldn't get that to work.

    I also had to orphan a few bones like upper chest but that didn't seem to matter too much as if it wasn't in the animation rig it probably wasn't doing anything anyway. You just need the absolute path to match exactly the original rig. You can check this because the transforms will match when you look at then in unity.

    And you don't need to rename all the bones, just those leading up to the prop, so in my case i did the whole right arm to the hand, but didn't need to change the fingers or the entire left arm. I've seen a few newer animations that just add the prop bones directly on to the root, that should make it a lot easier.
     
  27. lanlanluland

    lanlanluland

    Joined:
    Dec 11, 2019
    Posts:
    1
    I bought animation packs and character packs in the store and want to get weapon animations to work...
    finally found here
    Is there a solution now? :(
     
  28. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    13,565
    I've not been pursuing this issue (the thread is 7 years old), but as far as I know, "prop" bones are still not part of Mecanim ( see: https://docs.unity3d.com/ScriptReference/HumanBodyBones.html ), generic retargeting hasn't been implemented so nothing really changed in all that time.
     
    Jackrabbit82 likes this.
  29. Jackrabbit82

    Jackrabbit82

    Joined:
    Mar 13, 2013
    Posts:
    16
    Yep generally speaking I just avoid humanoid feature at all cost for this specific reason. The whole deal of character animations in a more complex project is that you will absolutely want or need prop bones or extras. I always sticked to generic. In generic setup you can still re-use all animation if you make sure the rig used is standardized within your creaction software pipeline. As long as it encompass all the scenarios it works.
    Otherwise when exceptions arise or are needed and cannot be added through other needs or in-engine prop bones (empty objects) then it's another ordeal entirely, either modify the base rig or export and sync up new object with rig.

    But I agree that for a 7 years old post this is still a huge loophole. We, old users have grown accustomed to the quirks, but unity is long overdue to move forward with a proper rig serializations that keeps solid references.
     
  30. General_Custard

    General_Custard

    Joined:
    Nov 19, 2016
    Posts:
    3
    Sorry for necro-posting, but in regards to clip transform offsets for Unity timeline, generic animations don't support this, but humanoid does. Seems like Unity really makes it difficult to do anything with best practices without finding some stupid loophole.