Load Avatars
Load 3D and 2D avatars into your Unity Scene.
In this guide, you learn how to load avatars into your Unity Scenes.
You can load full-body and half-body avatars into your Unity game. For both types of avatars you can follow the same procedure.
- 1.Create an instance of the
AvatarObjectLoader
. - 2.
var avatarUrl = "https://api.readyplayer.me/v1/avatars/632d65e99b4c6a4352a9b8db.glb";
AvatarObjectLoader avatarLoader = new AvatarObjectLoader();
avatarLoader.LoadAvatar(AvatarURL);
3. Receive the GameObject of the avatar in
CompletionEventArgs
of the OnCompleted
callback.See the code below for the completed example.
See the API Reference for a complete list of callbacks of the
AvatarLoader
. You can also find the code below in the
Assets\Samples\Ready Player Me Core\Samples\[VERSION_NUMBER]\AvatarLoading
.using ReadyPlayerMe.Core;
using UnityEngine;
namespace ReadyPlayerMe.Samples
{
/// <summary>
/// This class is a simple <see cref="Monobehaviour"/> to serve as an example on how to load Ready Player Me avatars and spawn as a <see cref="GameObject"/> into the scene.
/// </summary>
public class AvatarLoadingExample : 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;
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;
AvatarAnimatorHelper.SetupAnimator(args.Metadata.BodyType, avatar);
};
avatarLoader.LoadAvatar(avatarUrl);
}
private void OnDestroy()
{
if (avatar != null) Destroy(avatar);
}
}
}
You can load a 2D render of your avatar using the
AvatarRenderLoader
class which obtains a rendered image of your avatar via the Render API.- 1.Create an instance of
AvatarRenderLoader
. - 2.Call the
LoadRender()
method, passing the required arguments.
AvatarRenderLoader avatarRenderLoader = new AvatarRenderLoader();
avatarRenderLoader.LoadRender(url, scene, blendShapeMeshes, blendShapes);
See the code below for a complete example.
See the AvatarRenderLoader API Reference to learn more about
AvatarRenderLoader
and the function arguments.You can find an example usage of this code in the
Assets/Samples/Ready Player Me Avatar Loader/[VERSION_NUMBER]/AvatarRender/AvatarRenderExample
.The easiest way to save avatars in your project and package them with your build is using the Avatar Loader.
The Avatar Loader lets you download and save an avatar in your project in the Unity Editor.
- 1.Open the Avatar Loader window by choosing Ready Player Me > Avatar Loader.
- 2.Paste your avatar URL (or shortcode) into the Avatar URL or Shortcode field.
- 3.Optionally, check Use Eye Animations. This will add a component to the avatar GameObject.
- 4.Optionally, check Voice To Animation. This will add a component to the avatar GameObject.
- 5.Click Load Avatar into the Current Scene.
- 6.Your avatar loads into the current Scene at position (0,0,0).
- 7.The avatar prefab is stored in a new folder (name = avatar ID) in
Assets > Avatars
.
Last modified 1mo ago