Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Question Per Animation Avatar Mask

Discussion in 'Animation' started by ewoudwerf, Oct 31, 2023.

  1. ewoudwerf

    ewoudwerf

    Joined:
    Mar 19, 2016
    Posts:
    25
    Hey guys!
    I am making a game where I need humanoid characters to do two animations at once, walk/run/idle (mostly lower body) and wave/attack/etc (upper body and specific bones).

    I solved this by using two layers a lower body and upper body layer with an Avatar Mask.

    But I don't want some upper body animations to completely override the upperbody, for example if I have a character that waves with their right hand, I want the other hand to not get overridden (there are multiple more specific cases).
    And I also don't want to create so many avatar masks to make my animators more complicated.

    I found out you can create an avatar mask per animation clip. It only seems to be documented in this video and these docs.
    But when I use it, it doesn't mask at all, the body parts excluded from the mask just do the classic Unity Fetus Position.

    Am I using the per clip avatar masks wrong?
     
  2. MattVer

    MattVer

    Joined:
    May 19, 2013
    Posts:
    15
    Not entirely.

    As the documentation states:
    What that means is, when you create an AvatarMask for the clip, the animation of the bones etc that are not included in the mask you define gets removed.

    So if you have an AnimationClip where both the left and the right arm move, and you create a Mask that encompasses only the left arm, the animation of the right arm will be discarded/ignored from that AnimationClip, so when you play the clip, only the left arm will be animated.

    That's why when you play the animation that has only the left arm masked, the rest of the upper body remains still, because the animation data is not there.

    In your case, what you will need is 3 layers.
    Upper body, Lower body, and an Arms Layer, and the ArmsLayer should play the wave animation on waving clip with the arm masked.
    This way, the ArmsLayer will override or add the animation present in the AnimationClip, while the underlying upper body animation plays, and only the left arm motion gets added or override.
     
  3. ewoudwerf

    ewoudwerf

    Joined:
    Mar 19, 2016
    Posts:
    25
    I see that makes sense, but then you would still need to make individual layers with their own avatar masks right?
    Ideally, I'd like to have a layer without a specific Avatar Mask, that just uses the mask of the current clip. That would make my life a lot easier.
    I think the question is, can the clip avatar masks even be used that way?
     
  4. MattVer

    MattVer

    Joined:
    May 19, 2013
    Posts:
    15
    I haven't played with AvatarMasks in a while so I don't know if it'll work, but what you can try is to have the LowerBody, UpperBody, both with their respective masks, and add a generic Override or Additive layer that either has no AvatarMask , or a full body mask defined (I don't know which would work off the top of my head), and try to play your clips in that layer and see if the Animator will override only the bones that have an animation in the mask defined in the specific Animation Clip.

    You'll probably have to try a few different combinations to see if it'd work, but I think it is possible to accomplish it with a mask that overrides everything else, and create Masks in the individual clips to only the bones you want.