Links

AvatarObjectLoader

The AvatarObjectLoader class is used for loading and downloading avatar models and configuring the output.
AvatarObjectLoader was previously called AvatarLoader but has since changed with the introduction of the new modular Unity SDK or Unity SDK 2.0

Properties

Property
Type
Description
AvatarConfig
AvatarConfig
Avatar Configuration instance used when downloading avatars.
AvatarImporter
IAvatarImporter
Avatar Importer instance used for importing the GLB model.
​

Public Methods

Method
Returns
Description
LoadAvatar(string url)
void
Initiates avatar download and import operations. Takes an Avatar URL as a parameter.
Cancel()
void
Cancels the current avatar loading process. Fires OnFailed event with FailureEventArgs as OperationCancelled.
​

Events

Event
EventArgs
Description
OnCompleted
CompletionEventArgs
Called upon avatar loader success.
OnFailed
FailureEventArgs
Called upon avatar loading failure.
OnProgressChanged
ProgressChangedEventArgs
Called upon avatar loader progress change.

Example

using ReadyPlayerMe.AvatarLoader;
using ReadyPlayerMe.Core;
using UnityEngine;
​
namespace ReadyPlayerMe
{
public class AvatarLoadingExample : MonoBehaviour
{
[SerializeField]
private string avatarUrl = "https://api.readyplayer.me/v1/avatars/632d65e99b4c6a4352a9b8db.glb";
​
private GameObject avatar;
​
private void Start()
{
ApplicationData.Log();
var avatarLoader = new AvatarObjectLoader();
avatarLoader.OnCompleted += (_, args) =>
{
avatar = args.Avatar;
AvatarAnimatorHelper.SetupAnimator(args.Metadata.BodyType, avatar);
};
avatarLoader.LoadAvatar(avatarUrl);
}
​
private void OnDestroy()
{
if (avatar != null) Destroy(avatar);
}
}
}