Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Include extra gameobjects in avatar mask

Discussion in 'Animation' started by Compressed, Feb 9, 2015.

  1. Compressed

    Compressed

    Joined:
    Sep 20, 2014
    Posts:
    59
    I have a base humanoid model imported into Unity from the blender. The model has some animations on it. In the animator i added two layers, one which plays running-walking animations and such, and another layer above it (set to override) which handles hand waving and such. In that second layer i added a mask where i have only the upper body enabled, so i can play hand waving and walking animations at the same time. This works ok.
    Then i add a new empty game object into the character's hand (or in other words, make the hand game object the new gameobjet's parent). Because the hand is that objects parent, when the hand moves during animations, the child empty object moves with it as well. So far so good.
    Now in the mecanim i edited the hand waving animation and in this animation i moved (animated) that newly added game object.
    But the problem is, it doesn't move. If i remove the Mask from the animation layer (so the Mask is set to none), it works no problem, but with the mask in it it does not. This is caused by the fact, that in the avatar mask i have the hand selected as green so it animates the hand, but i don't have the new gameobject selected in that mask avatar, so it doesn't animate it.

    The question is, how can i include this gameobject in the avatar mask? (It is not visible in the transform menu under the avatar edit)

    thanks
     
  2. Mecanim-Dev

    Mecanim-Dev

    Unity Technologies

    Joined:
    Nov 26, 2012
    Posts:
    1,675
    Did you try to create a new mask with your modified rig that include your new game object?
     
  3. Compressed

    Compressed

    Joined:
    Sep 20, 2014
    Posts:
    59
    The game object isn't part of the model itself (fbx), i added it in the unity hierarchy editor.
    So the object is saved in a prefab of that model but i'm not sure if you can even create avatar for a prefab..?
     
  4. Mecanim-Dev

    Mecanim-Dev

    Unity Technologies

    Joined:
    Nov 26, 2012
    Posts:
    1,675
    Of course you can.

    We do have the AvatarBuilder class that allow you to create custom avatar even at runtime
    http://docs.unity3d.com/ScriptReference/AvatarBuilder.html

    That been said creating a custom avatar is not an easy task. Is there any reason why you wouldn't add this new game object directly in blender? This way the avatar from the model importer would contain your game object so you will be able to create a new avatar mask that control this object too.
     
    theANMATOR2b likes this.
  5. Xelnath

    Xelnath

    Joined:
    Jan 31, 2015
    Posts:
    399
    I too am trying to create a custom AvatarMask.

    I have a heirarchy of Unity Objects - one for each sprite. Then I have a series of complex animations. (Walk, Run) then another set of additive animations (Hold up umbrella, Raise tail).

    Now I want to mix them together. However, I cannot find any examples of creating a custom AvatarMask - which seems to be vital for allowing me to blend my creatures's base animations (run, walk, etc) with secondary animation features (Raise umbrella, curl up tail).

    Can you provide an example of custom AvatarMask creation?

    I've been able to create an avatar with this code block:
    Code (csharp):
    1.  
    2.         var avatar = AvatarBuilder.BuildGenericAvatar(tempHandcraftedPrefab, "");
    3.         avatar.name = handcraftedPrefab.name;
    4.         AssetDatabase.AddObjectToAsset(avatar, handcraftedPrefab);
    5.  
    However, I have no idea how to generate an AvatarMask to use in Mechanim and can't find any tutorials on the subject yet.

    Edit:

    I have followed the steps outlined here:

    https://unity3d.com/learn/tutorials/modules/beginner/animation/avatar-masks

    However, when I select the Avatar created by the avatar builder mentioned above, it doesn't show me any checkboxes to select.

    axegunavatar.png
     
    Last edited: Mar 23, 2015
  6. 00christian00

    00christian00

    Joined:
    Jul 22, 2012
    Posts:
    1,032
    Hi Mecanim.dev,
    there is a bug in the avatar mask for a humanoid avatar if you don't use the humanoid mask in Unity 4.6 latest patch.
    If you create a mask specifying the bones instead of using the humanoid mask and use it on a override layer, it will override everything regardless of what bones you chose.
    The only difference is that if you chose the bones in the mask they will be animated, the bones outside the mask will stay frozen but still override the base layer.
    Can you have a look at it? It it having the issue with every avatar.
    If you use a humanoid mask, it works as expected.
     
  7. 00christian00

    00christian00

    Joined:
    Jul 22, 2012
    Posts:
    1,032
    Nevermind, I found the issue.
    I was overriding a generic animation on a humanoid one, but didn't deselect the humanoid parts of the mask(I didn't have them, so I didn't think of disabling them).
    Once I deselected them everything works as it should.
    Nice to know you can combine humanoid and generic animation, really powerful stuff.
    This way I can also add scale animations to humanoid which are otherwise disabled.
     
    theANMATOR2b likes this.