- Home /
Question by
thijsvdvijver · Apr 22, 2021 at 10:48 AM ·
animationunity 53dmasking
(3D) Generating avatar masks automatically from animation
Dear everyone,
I have a rig with a lot of bones along with a lot of ways to animate these. The result of this is having to make hundreds of avatar masks for this rig by hand (every animation needs its own mask). I was wondering if there was a way to automate this process by checking what bones move in an animation somehow and the generating the mask for this animation automatically. I have found a code snippet that seems promising but I am new to Unity and this code snippet is without context as I cannot find the project it belongs to. Thank you in Advance!
static void CreateMask()
{
Animator animator;
if(!Selection.activeGameObject)
{
return;
}
animator = Selection.activeGameObject.GetComponent<Animator>();
if(!animator)
{
return;
}
List<Transform> transforms = new List<Transform>();
AvatarMask avatarMask = new AvatarMask();
animator.GetComponentsInChildren<Transform>(true,transforms);
avatarMask.transformCount = transforms.Count;
int index = 0;
foreach(Transform transform in transforms)
{
avatarMask.SetTransformPath(index, AnimationUtility.CalculateTransformPath(transform,animator.transform));
avatarMask.SetTransformActive(index, true);
index++;
}
ScriptableObjectUtility.CreateAssetWithSavePanel<AvatarMask>(avatarMask,"Create Mask",animator.name+".mask","mask","Create a new Avatar Mask");
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613032627im_/https://answers.unity.com/themes/thub/images/avi.jpg)