- Unity 2020 or higher
- Ready Player Me Unity SDK found here
- details for import and setup are in the README.md
This guide assumes that you have already installed the Ready Player Me Unity SDK that includes the Core and Avatar Loader modules, which which required for loading our avatars.
-
Open up your Unity project
-
Import one of the
TPose.fbx
files.
e.g.Masculine_TPose.fbx
-
Go to import settings Rig tab and adjust the following settings in the Inspector window
- Animation Type = Humanoid
- Avatar Definition = Create from this model
-
Import the animation fbx files e.g.
F_Dances_001.fbx
-
Go to import settings for the animations Rig tab and adjust the following settings in the Inspector window
-
With the import settings still open switch to the Animation tab and adjust the following settings
-
Create a new animator controller
-
Repeat the steps 1 - 6 for the
Feminine_TPose.fbx
and animation files
To apply the animations on a runtime loaded avatar we will use a slightly modified version of the AvatarLoaderExample.cs.
Firstly we create a new function called SetAnimatorController
for setting the animator controller based on the loaded avatars outfit gender.
e.g. Masculine avatar should have masculine animator controller
// This method is used to reassign the appropriate animator controller based on outfit gender
private void SetAnimatorController(OutfitGender outfitGender)
{
var animator = avatar.GetComponent<Animator>();
// set the correct animator based on outfit gender
if (animator != null && outfitGender == OutfitGender.Masculine)
{
animator.runtimeAnimatorController = masculineController;
}
else
{
animator.runtimeAnimatorController = feminineController;
}
}
Next we call this function from the AvatarLoader.OnCompleted callback
avatarLoader.OnCompleted += (_, args) =>
{
avatar = args.Avatar;
SetAnimatorController(args.Metadata.OutfitGender); // <--------------- NEW
};
The end result will be an AvatarLoader script that will look something like this.
using ReadyPlayerMe.AvatarLoader;
using ReadyPlayerMe.Core;
using UnityEngine;
public class TestAvatarLoader : MonoBehaviour
{
[SerializeField, Tooltip("Set this to the URL or shortcode of the Ready Player Me Avatar you want to load.")]
private string avatarUrl = "https://api.readyplayer.me/v1/avatars/638df693d72bffc6fa17943c.glb";
private GameObject avatar;
// Add 2 editable fields to store the new masculine and feminine animator controllers
[SerializeField] private RuntimeAnimatorController masculineController;
[SerializeField] private RuntimeAnimatorController feminineController;
private void Start()
{
ApplicationData.Log();
var avatarLoader = new AvatarObjectLoader();
// use the OnCompleted event to set the avatar and setup animator
avatarLoader.OnCompleted += (_, args) =>
{
avatar = args.Avatar;
SetAnimatorController(args.Metadata.OutfitGender); // <--------------- ADDED
};
avatarLoader.LoadAvatar(avatarUrl);
}
// This method is used to reassign the appropriate animator controller based on outfit gender
private void SetAnimatorController(OutfitGender outfitGender)
{
var animator = avatar.GetComponent<Animator>();
// set the correct animator based on outfit gender
if (animator != null && outfitGender == OutfitGender.Masculine)
{
animator.runtimeAnimatorController = masculineController;
}
else
{
animator.runtimeAnimatorController = feminineController;
}
}
private void OnDestroy()
{
if (avatar != null) Destroy(avatar);
}
}