Avatar System - How to get VRMs working with Emergence
Last updated
Last updated
An example of this can be found in the Emergence Sample Project, check it out here!
If you haven't read how to get avatars into Emergence Avatar System (EAS) yet, this link will show you how to do so!
This will teach you how to allow users to load their game ready avatars from the EAS system into your game world! Welcome to Interoperability!
Emergence uses VRM4U to get VRM meshes into your game at runtime. A precompiled version can be found in our sample project zip, or in the "PrecompiledForBlueprintOnly" zips, both of which can be found on our github. It is important to get a version that includes the source files, rather than their usual download page, as the Emergence VRM Support plugin requires the source code to interact with.
Once you have downloaded VRM4U, extract the VRM4U folder from the plugin folder in the zip to the plugin folder of your project.
Then, open your Unreal Engine project and go to the plugin configuration window. From here, enable the “VRM4U” plugin and the “Emergence VRM Support” plugin and then restart the editor.
When you restart, you will be asked if you want to rebuild a number of unbuilt modules - click “Yes”. Do not be concerned if this takes a while, there is a lot of code to compile!
When it finishes, Unreal Engine should launch as usual.
We need a way to show a VRM in-game at runtime.
You’ll need a skeleton that is compatible with VRM4U, rigged in a way that will work for your game with animations. Using Unreal Engine’s “Third Person Example” as a basis, we’ve found the easiest way to do this is the following…
Firstly, find the skeleton of the default third person mannequin:
Open it and find the "Retarget Manager" (you may need to open it at the top of the window). Under the "Select Rig" dropdown, select Humanoid. The bones should automatically map in the list below.
Then find the animation blueprint of the default third person mannequin:
Right click it, and click “Retarget Anim Blueprints” > “Duplicate Anim Blueprints and Retarget”:
From here, select the “SKEL_VRoidSimple” skeleton (you may need to enable “show plugin content” under “View Options” to see it). Under “New Asset Name”, you can specify how you want it to name the new assets, based on the names of the old assets.
For example, this will create all the new assets with VRM in the name:
The new assets created:
Next, you’ll need to set up a character to receive the animations. The way this works with VRM4U (and our extra simplification / integration code) is kinda odd so make sure to read each step carefully.
Effectively, you’re going to have a hidden mesh that actually does all of the animating, and then an additional visible mesh which will have the player’s VRM avatar loaded onto it at runtime which will copy the hidden mesh - weird, right?
For this example, the default character skeletal mesh is going to act as our visible mesh, and we’re going to attach to this a child “EmergenceVRMMesh” component. It must be the child of the skeleton it's going to be copied by, as the component looks to its parent to find this skeleton.
You want to click on the EmergenceVRMMesh and set the Anim Class to the class you created in the last section, and Skeletal Mesh to the SK_VRoidSimple:
Remember, the location or rotation of this mesh shouldn’t matter as it won’t be visible.
Now that you have the components set-up and the URL of the model, all thats left to do is load the the model.
To display the player’s persona, we first need to get a URL to download it from. To do this, we need to get the player’s persona data. The Emergence service provides the OnCachedPersonaUpdated event, which is called with the new persona’s data every time a new persona is added. This example below, we are loading the Avatar automatically when a Persona is selected. But as a Developer, you might want to only load your Avatars after a certain delay or after a certain event happens. We've built this so you as the Developer have control over when the Loading happens. This is an example that automates it whenever a user updates their selection.
Something to point out here, is that the Avatar's files will be downloaded from the blockchain via the "GetDataFromURL" node. This can take a few moments, as files can be rather large. So expect a few moments before the Avatar is ready and loaded in your game!
This step changes the skeletal mesh and the animations should work now. Congratulations, you have avatars loading!