In this blog, you’ll see how to configure your Ready Player Me Avatar in Unity during runtime. If you don’t know about Ready Player Me or if you want to know how to create your avatar, then you should definitely watch this video before continuing with this blog.
Let’s begin by creating a new Unity Project and importing the Ready Player Me SDK.
Alright now that you have the project set up with Ready Player Me SDK, let’s see how to use the Avatar Configure file.
Avatar Config Files are scriptable objects that you can create and use to load an avatar in the configuration defined by you.
To test this,
With that, you have learnt to load an avatar using the avatar config scriptable object. But what if you want to load an avatar at runtime? That’s exactly what you’ll learn in the next section.
There are two ways of loading Avatar at runtime. You can either create an Avatar Config file and use it to load an avatar or directly define it in the script. In this section, you’ll see how to load the avatar using the latter method.
First, create a new C# script and name it as RuntimeAvatarLoader. Next, copy the following code into your script.
The script has a SerializeField where we need to provide the URL of the Avatar. On start, the script will create a new Avatar Config file and set it up as per the configuration written in the script. Only when the function LoadAvatar() is called, the script uses the URL to load the avatar into the scene.
Open the SampleScene, create an empty GameObject and name it AvatarLoader → add the RuntimeAvatarLoader script to it.
Now go to the ReadyPlayerMe dashboard, copy the Avatar link and paste it into the Avatar URL field of the RuntimeAvatarLoader component.
Then, add a UI button by right clicking on the Hierarchy window and select UI → Button TextMeshPro. Also, replace the button text with “Load Avatar”.
Finally, select the Button GameObject → navigate to the Button component → under the On Click event, click on the Plus sign ➕ → drag and drop the LoadAvatar GameObject. From the drop-down select RuntimeLoadAvatar → LoadAvatar ().
To test this, all you need to do is press the Play button and then press the LoadAvatarUI button in the Game window.
With that, you were able to load the avatar at run time with a predetermined configuration.
Now that you know how to change the parameters of an avatar either by using the scriptable objects or via a script, you can create a dynamic experience for the users. Ready Player Me has also provided an example scene where the LOD of the avatar changes based on the distance of the camera from that avatar. This is really helpful when you have to optimize your game/experience. There are many more use cases for using the API during runtime, feel free to explore them.
If you've enjoyed the insights shared here, why not spread the word? Share the post with your friends and colleagues who might also find it valuable.
Your support means the world to us and helps us create more content you'll love.