Version: 2023.1
LanguageEnglish
  • C#

AvatarBuilder.BuildGenericAvatar

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Declaration

public static Avatar BuildGenericAvatar(GameObject go, string rootMotionTransformName);

Parameters

go Root object of your transform hierarchy.
rootMotionTransformName Transform name of the root motion transform. If empty no root motion is defined and you must take care of avatar movement yourself.

Description

Create a new generic avatar.

All transforms under the root game object will be part of this generic avatar.

using UnityEngine;
using UnityEditor;

public class Example : MonoBehaviour { void Start() { GameObject activeGameObject = Selection.activeGameObject;

if (activeGameObject != null && activeGameObject.GetComponent<Animator>() != null) { Avatar avatar = AvatarBuilder.BuildGenericAvatar(activeGameObject, ""); avatar.name = "InsertYourName"; Debug.Log(avatar.isHuman ? "is human" : "is generic");

Animator animator = activeGameObject.GetComponent<Animator>() as Animator; animator.avatar = avatar; } } }