Search Unity

AvatarMask can't import sekeleton from generic Avatar

Discussion in 'Editor & General Support' started by Estecka, Nov 7, 2018.

  1. Estecka

    Estecka

    Joined:
    Oct 11, 2013
    Posts:
    62
    I want to make an avatar mask for a generic GameObject, but it doesn't come from a 3D object, so I don't have an Avatar ready to use.

    I heard of `AvatarBuilder.BuildGenericAvatar`.
    I tried using it on my game object with this EditorWindow :
    Code (CSharp):
    1. #if UNITY_EDITOR
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using UnityEngine;
    5. using UnityEditor;
    6.  
    7. namespace EsteckaEditor {
    8.     public class AvatarFromObject : EditorWindow {
    9.  
    10.         [MenuItem("Tools/Avatar")]
    11.         static public void Init(){
    12.             EditorWindow.GetWindow<AvatarFromObject>(true, "Avatar builder", true).Show(true);
    13.         }
    14.  
    15.  
    16.         GameObject source;
    17.        
    18.         void OnGUI(){
    19.             source = (GameObject)EditorGUILayout.ObjectField(source, typeof(GameObject), true);
    20.  
    21.             if (source) {
    22.                 Avatar av = AvatarBuilder.BuildGenericAvatar(source, source.name);
    23.                 if (GUILayout.Button("Create")) {
    24.                     AssetDatabase.CreateAsset(av, "Assets/new Avatar.asset");
    25.                 }
    26.  
    27.             }
    28.         }
    29.  
    30.     }
    31. }
    32. #endif
    This succesfully create an Avatar in the asset folders. When I look at the file through a text editor, I do find the hierarchy of my gameobject mentionned in there.
    I drag the newly generated avatar into a new AvatarMask, but the "Import Skeleton" button does not appear, so I can't edit my mask...

    What did I do wrong ?
     
    ModLunar likes this.
  2. ModLunar

    ModLunar

    Joined:
    Oct 16, 2016
    Posts:
    374
    I'm finding the exact same problem today. I'm gonna dig through the Unity CS Reference to see why the "Import Skeleton" button is still disabled after dragging the Avatar reference onto the field just above it..
     
  3. ModLunar

    ModLunar

    Joined:
    Oct 16, 2016
    Posts:
    374
    upload_2020-4-25_14-2-57.png

    Found it.

    It's in AvatarMaskInspector.cs around line 551 (shown in the above screenshot).
    It only activates the button if it can find a ModelImporter at the path of the Avatar asset, which is clearly wrong. The point of why we made the Avatar creation code for ourselves is cause we wanted to remove that restriction, and use Avatars with generic Transform hierarchies! Haha

    I'm going to write something through reflection to call Line 554 in the screenshot above, and maybe we can submit a bug report if we have the time to get this behavior fixed.
     
    Xylitogum likes this.
  4. ModLunar

    ModLunar

    Joined:
    Oct 16, 2016
    Posts:
    374
    Okay hmm.. so I don't remember the exact details, but it was quite a struggle to get my custom Avatars to really be useful in any way. For now, I'm using my animation layers without avatar masks, so it's okay.

    In general, a lot of the deep animation stuff in Unity is hidden in their C++ implementation, so we can't even get through to a lot of the Avatar fields in C# even with Reflection. So I had to stop my endeavors on making it easier to create generic Avatars for now.
     
  5. LeFx_Tom

    LeFx_Tom

    Joined:
    Jan 18, 2013
    Posts:
    88
    I just ran into the exact same issue and it's super painful. I wonder if Unity will ever care enough to rework/improve those workflows because the Animator is basically a very powerful tool...but some workflows are really tedious and cumbersome...
     
    ModLunar likes this.
  6. adishee

    adishee

    Joined:
    Jun 2, 2020
    Posts:
    8
    This ever get fixed. It's really vexing