Legacy Documentation: Version 5.0
Language: English
  • C#
  • JS

Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

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

Sumbission failed

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

Close

Cancel

Switch to Manual
public static function BuildGenericAvatar(go: GameObject, rootMotionTransformName: string): Avatar;
public static Avatar BuildGenericAvatar(GameObject go, string rootMotionTransformName);

Parameters

goRoot object of your transform hierarchy.
rootMotionTransformNameTransform 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.

function Start() {
	var go: GameObject = Selection.activeGameObject;
	
	if (go != null && go.GetComponent.<Animator>() != null) {
		var avatar: Avatar = AvatarBuilder.BuildGenericAvatar(go, "");
		avatar.name = "Bob";
		Debug.Log(avatar.isHuman ? "is human" : "is generic");
	
		var animator: Animator = go.GetComponent.<Animator>() as Animator;
		animator.avatar = avatar;
	}
}