Loading 3D Avatars
Code sample that demonstrates how to load an avatar at runtime.
Last updated
Code sample that demonstrates how to load an avatar at runtime.
Last updated
These examples have been tested in Unity 2020.3LTS and newer versions.
Open the Unity Package Manager and find the Ready Player Me Core Package.
You can find the code samples on the package manager's right side. Find the AvatarLoadingSamples and click Import.
The AvatarLoadingExample.cs
script demonstrates how to load one avatar at runtime.
Scene and Code
Assets/Samples/Ready Player Me Core/[VERSION_NUMBER]/AvatarLoadingSamples/AvatarLoading
Open and play the AvatarLoadingExample Scene. The example loads an avatar (and includes a Debug Log panel described below).
Open the RuntimeExample.cs script, which loads the avatar as follows.
Creates an instance of AvatarLoader: var avatarLoader = new AvatarObjectLoader();
Defines the OnCompleted()
callback for the AvatarObjectLoader
this is called when loading has successfully completed.
Adds an Avatar Configuration to the AvatarObjectLoader
from Assets > Plugins > ReadyPlayerMe > Resources > Data > AvatarConfigurations.
Calls LoadAvatar()
with the URL for the avatar to load. This operation will download, import, and load the avatar model into the Scene.
This code sample demonstrates how to load multiple avatars at runtime.
Scene and Code
Assets/Samples/Ready Player Me Corer/[VERSION_NUMBER]/AvatarLoadingSamples/MultipleAvatarLoading
Open and play the MultipleAvatarLoadingExample Scene. The example loads several avatars (and includes a Debug Log panel described below).
Open the MultipleAvatarLoadingExample.cs script.
Notice that there is only one avatar URL.
Loading works in the same way as for one avatar and is repeated for every avatar to load.
The variations in the avatar are created by using a list of different configurations that are applied in OnCompleted() -> OnAvatarLoaded()
after the avatar has been loaded.