How to use Unity Avatar SDK

How to use Ready Player Me Unity SDK.

Requirements

  • The SDK supports Unity 2018LTS and newer versions of the Unity3D game engine.

  • A valid avatar URL created from Ready Player Me to import an avatar to a Unity scene.

For IOS builds Microphone Usage Description field in Player Settings must be filled with an appropriate message. VoiceHandler component requires microphone permission and if this area is not filled the build will fail. To build without mic permission, simply remove this script.

For Unity URP projects, make sure to add GLTF Utility shaders into Always Included Shaders list in Graphics Settings.

How to use

Loading Avatars

RPM Unity SDK editor window can be launched from Ready Player Me > Avatar Loader menu. To create and save your avatar in editor time, simply paste your avatar URL and click on Load Avatar button.

To be able to load an avatar during play time, create an instance of AvatarLoader and call LoadAvatar method from the instance with the URL of the avatar to load.

private void LoadAvatar()
{
AvatarLoader avatarLoader = new AvatarLoader();
avatarLoader.LoadAvatar(avatarUrl, AvatarLoadedCallback);
}
private void AvatarLoadedCallback(GameObject avatar)
{
Debug.Log("Avatar Loaded!");
}

This operation will download and load the avatar model to the scene and via a callback method, you can get access to the avatar game object in the scene.

You can find an example of this function in Assets\Plugins\Wolf3D Ready Player Me SDK\Examples\Runtime Avatar Loader\RuntimeTest scene.

Ready Player Me updates users avatar on the same URL. If you re-customize your avatar, change your avatar from full-body to half-body these changes are reflected on the same URL. Be mindful of this when loading multiple avatars.

Create avatars directly in Unity using WebView (Mobile Only)

This feature lets users create Ready Player Me avatars directly in a WebView displayed within Unity.

This is achieved by displaying avatar creation and customization in a seamless interface allowing you to embed Ready Player Me avatar creation inside your Unity application.

Want to see how it looks like? Check these short guides below:

Android Guide
IOS Guide

An example of how Webview is used and avatar is loaded afterwards can be found at "Assets/Plugins/Wolf3D Ready Player Me SDK/Examples/Webview".

If you are a RPM partner you can edit the target URL to address your specific domain name from the WebView Partner Editor window, which can be found under Ready Player Me menu.

WebView is tested on Unity 2018 LTS and newer versions. You might have errors in prior versions of Unity.

WebView plugin is mobile only and works on Android, IOS systems. VR platforms are not yet supported.

private void LoadWebview()
{
Webview webview = new Webview();
webview.OnAvatarCreated = AvatarCreatedCallback;
webview.CreateWebview(this);
}
private void AvatarCreatedCallback(string url)
{
Debug.Log($"Avatar Url received: { url }");
}

API documentation

AvatarLoader

The main class used for loading and downloading avatar models and configures the output.

public void LoadAvatar(string url, Action<GameObject> callback = null)

  • Initiates avatar download and import operations.

public int Timeout

  • The timeout value for avatar download request.

Webview

Component that loads the In-Unity Browser targeting RPM website.

public void CreateWebview(MonoBehaviour parent)

  • Creates the WebView window. This method takes a MonoBehaviour game object as a parent to be attached.

public void SetScreenPadding(int left, int top, int right, int bottom)

  • Sets the screen padding of the WebView window. Default is 0 for all sides.

public Action<string> OnWebviewStarted

  • Event to call when WebView starts, receives string as a status message.

public Action<string> OnAvatarCreated

  • Event to call when avatar is created, receives GLB url.

Extras

Ready Player Me Unity SDK comes with a few useful extra components to help you setup your avatar. You can add these components on your avatar object from component menu or in runtime using Unity's AddComponent method.

EyeRotationHandler

Rotates and blinks the eyes of the avatar randomly. Blink delay can be set from the component inspector.

private void AvatarLoadedCallback(GameObject avatar)
{
avatar.AddComponent<EyeRotationHandler>();
}

VoiceHandler

Uses microphone feedback to animate the mouthOpen blend shape via amplitude of the voice. Animation will have 1 second delay due to minimum recording length.

private void AvatarLoadedCallback(GameObject avatar)
{
avatar.AddComponent<VoiceHandler>();
}

Dependencies

Dependencies are already included in the .unitypackage file, if you are using an older or a newer versions of these dependencies please backup your project before making changes.