Search Unity

Help! Root motion breaks mesh

Discussion in 'Animation' started by tfalves, Sep 25, 2022.

  1. tfalves

    tfalves

    Joined:
    Jun 27, 2014
    Posts:
    29
    Hello everyone,

    I have been struggling with an issue for almost a month now. I've tried everything I could think of, but I still can't understand what's happening.

    You can see, from the images below, that parts of the mesh animate independently, and at its own pace.
    Here are some details about the workflow:
    1. My character is using a blender rigify armature, which contains some additional bones that control the hair.
    2. I am importing it to unity using a generic animation type (not a humanoid).
    3. If I set an avatar it starts breaking, as shown
    4. If I don't set an avatar, the animation shows just fine, but then there is no actual motion (the circle below the character does not move with the character, and the animation resets to its original place once the loop finishes). This is also a problem, because I will need to mask parts of the character
    If you have any hint about why this might be happening, please help, I am pulling my hair here :(

    1.png 2.png 3.png
     
  2. Nathanieljla

    Nathanieljla

    Joined:
    Apr 18, 2014
    Posts:
    97
    When you say that setting an avatar breaks the animations, are you creating an avatar from the file or copying the avatar? If this is an issue when creating an avatar from the file then here's a few things I would check.
    1. In the model import settings turn OFF "Sort hierarchy by name".
    2. Drag the character into the hierarchy and examine hierarchy, does anything look like it's missing?
    3. Are the hair joints children of the head bone or are they in a separate branch from the character skel?
    4. When things get really confusing I like to import my FBX back into my my 3D app to verify the data looks good.
    5. Make sure every bone has animation data on it. if you skeleton is controlled by another rig in Blender, then make sure the FBX exporter has "bake animation" enabled.

    If you're using one file to create the avatar, and using the other files for the animation data, then make sure their hierarchies match. Drag both into the Hierarchy tab and compare. I always organize my skeleton data to come first in the file hierarchy, followed by the mesh data. If your animation files don't include the meshes, and the meshes comes first in the file that creates the avatar then you're going to have issues.
     
  3. tfalves

    tfalves

    Joined:
    Jun 27, 2014
    Posts:
    29
    Hi! Thanks for the help.

    These are the settings I use for the rig

    Screenshot 2022-09-26 at 2.14.28 PM.png

    1. Disabled it, still have the problem
    2. What do you mean by "Drag the character into the hierarchy"?
    3. Joints are parented to the head bone
    4. Imported the fbx back into Blender, everything is looking fine
    5. Baked animation is enabled and the bones are keyed
    It's weird, because only the hair (which is part of the same mesh as the head) moves like this. The two things seem to animate at different rates. I am still believing this might be related with the avatar, as the generic avatar does not allow me to specify which bones are which.
     
  4. Nathanieljla

    Nathanieljla

    Joined:
    Apr 18, 2014
    Posts:
    97
    Drag the character into the hierarchy = take your asset from the project tab and drag it into the current scene (the hierarchy tab), so you can expand the object and view it's structure.

    Generic characters are really the most flexible. With a humanoid, you get some extra, automatic features, like animation re-targeting, mirroring, etc, but there's nothing about the generic character that should be an issue. You can still use the humanoid character as long as all your extra bones aren't in the middle of the humanoid structure, i.e. they must be leaf bones. For example, you can have twist bones, as long as they're not between the arm and forearm. If your character works as humanoid, minus the hair and the hair are all children of the head, then the only thing you'll need to do is create an avatar mask, and make sure the extra bones are turned on in the mask. Then inside of the import settings, for each clip, you'll need to assign the mask.

    If this character is something you can share, feel free to post the FBX and I'll examine it.
     
  5. tfalves

    tfalves

    Joined:
    Jun 27, 2014
    Posts:
    29
    Oh ok, you meant into the scene hierarchy, sorry, I was thinking about something else.

    I had never tried masks directly with the animation clip before today. I have been trying them, but it seems that I can't find any suitable combination that works. I am starting to think that the problem might lie in the way the rig was built.
    This is the first time I am trying to do root motion, I never faced these issues before.

    P.s. I replied to your DM.
     
  6. Nathanieljla

    Nathanieljla

    Joined:
    Apr 18, 2014
    Posts:
    97
    Okay, I *think* is see what's going on. Your hair and your body are in two different hierarchies. in the image, #1 is the hair skel, #2 is the body skel. When the root node is set you can see the hair is getting a double transform. I.e. it plays it's transform data, then the root motion is applied to everything. I would argue that the correct fix is to put the hair bones inside of the body hierarchy. However, maybe you need them to be separate? In that case I think you could fix this game side with the animation rigger package. You could then make the bones of hair hierarchy match the transforms of the body hierarchy.

    When rigging for games I generally have an optimized game skeleton for export, and then the skeleton I animate.
    Char_Hair_Issue.PNG
     
  7. Nathanieljla

    Nathanieljla

    Joined:
    Apr 18, 2014
    Posts:
    97
    Actually, I just turned off processing for the root of the hair hierarchy and that seems to fix it. I'd probably make a mask for this, so you can quickly assign it to each anim.

    upload_2022-9-26_11-38-18.png
     
  8. tfalves

    tfalves

    Joined:
    Jun 27, 2014
    Posts:
    29
    No, you are correct, I do not need this separation. Somehow I must have done something wrong in Blender. This was the first time I added custom bones to Rigify, so I must be missing something that is actually making these bones not part of the correct hierarchy.

    Below you can see the hierarchy. I believe I need to do some more reading about this, because apparently this does not produce the result I expected. By the way, a little further down the DEF bones start to appear. I believe these should not be in this hierarchy, correct?
    Screenshot 2022-09-27 at 12.08.15 AM.png
     
    Last edited: Sep 26, 2022
  9. tfalves

    tfalves

    Joined:
    Jun 27, 2014
    Posts:
    29
    I just ran a quick test, and this seems to fix the problem indeed! I can't thank you enough for this!
    I will try again tomorrow with some other animations to see if the end result is what is expected.
     
  10. tfalves

    tfalves

    Joined:
    Jun 27, 2014
    Posts:
    29
    Hello!
    I have been trying around, and it seems like this did the trick, though I am having similar troubles with other animations.
    I feel that using rigify was more of a problem than a benefit. It simply does not seem to play well with Unity's mechanim system.
     
  11. Nathanieljla

    Nathanieljla

    Joined:
    Apr 18, 2014
    Posts:
    97
    Unfortunately I'm not familiar with Blender, so I can't comment on Rigify. e.g. not sure what DEF bones are. I would say that turning the transform off from the mask is more of a quick fix vs. the ideal fix of fixing the hierarchy.
     
  12. tfalves

    tfalves

    Joined:
    Jun 27, 2014
    Posts:
    29
    Agree. I need to reconsider this specific model. I'll either rebuild the rig, or create a custom rig from scratch.
     
  13. MrKsi

    MrKsi

    Joined:
    Aug 30, 2020
    Posts:
    139
    I have a similar situation now. Have you found a solution to the problem?
    https://forum.unity.com/threads/weapon-animation-breaks-if-you-turn-it-off-how-to-fix-it.1346258/
     
  14. tfalves

    tfalves

    Joined:
    Jun 27, 2014
    Posts:
    29