Using AvatarMeshHelper in Unity

I’m using AvatarMeshHelper in my own project. My prefabs are built on the Shooter example armature, with my own RPM meshes used as defaults.
I have code to download medium-res single-mesh avatars.
AvatarMeshHelper throws an error; it seems to want an array of skinned meshes instead of pulling a mesh from a downloaded Ready Player Me avatar.

I’m not using the full res multipart RPM avatar because I have the user choose their customization in a previous scene, then I download the medium res single mesh version using a config file.

How can I solve this?

I’m using Smartfox, but this is for the local player. I have a network player script attached to my Avatar prefab.

public void SetPlayer()
{
    // load the medium res avatar, then transfer mesh to Game Creator armature
    Debug.Log("avatar URL is " + rpmURL);

    if (rpmURL.Length > 0)
    {
        AvatarObjectLoader loader = new AvatarObjectLoader();
        loader.LoadAvatar(rpmURL);
        loader.AvatarConfig = config;
        loader.OnCompleted += (sender, args) =>
        {
            GameObject targetPrefab = this.gameObject;
            if (VariablesManager.ExistsGlobal("avatar_model"))
            {
                //switchMeshActionSet.Execute(); // post-load actions in game.
                AvatarMeshHelper.TransferMesh(args.Avatar, gameObject, null);
            }
            else
            {
                Debug.LogError("Error: something wrong with avatar id URL or model.");
            }
        };

    }
}

Error:

|Severity|Code|Description|Project|File|Line|Suppression State|Details|
|---|---|---|---|---|---|---|---|
|Error|CS1503|Argument 2: cannot convert from 'UnityEngine.GameObject' to 'UnityEngine.SkinnedMeshRenderer[]'|Assembly-CSharp|D:\~Work\~Unity Dev\hundo\hundo x Ruby Room Smartfox v2 addressables\Assets\GameScripts\NetworkPlayer.cs|72|Active||

Screens - Left is Smartfox compatible based on downloaded RPM avatar as default; right is the Photon RPM multiplayer resource.

I succeeded by manually capturing the avatar skins, and noticing there’s two versions of Unity’s get component; one is plural and captures arrays. :disguised_face:

public void SetPlayer()
{
    // load the medium res avatar, then transfer mesh to Game Creator armature
    Debug.Log("avatar URL is " + rpmURL);

    if (rpmURL.Length > 0)
    {
        AvatarObjectLoader loader = new AvatarObjectLoader();
        loader.LoadAvatar(rpmURL);
        loader.AvatarConfig = config;
        loader.OnCompleted += (sender, args) =>
        {
            lqAvatar = args.Avatar;
            if (lqAvatar != null)
            {
                SkinnedMeshRenderer[] newSkins = gameObject.GetComponentsInChildren<SkinnedMeshRenderer>();
                Animator animator = gameObject.GetComponent<Animator>();
                AvatarMeshHelper.TransferMesh(lqAvatar, newSkins, animator);
                DestroyAvatars();
            } 
        };
    }
}
1 Like

Partial success. Running two instances on one computer (one build and in-Unity), the avatars load, both change both the local and remote players to the same avatar - whichever is the local player’s avatar in that instance is also added to the remote player’s avatar instance.

1 Like

Good to hear you solved this :slight_smile:
Yes, the TransferMesh method requires the SkinnedMeshRenderer type. This is the method signature:
TransferMesh(GameObject source, SkinnedMeshRenderer[] targetMeshes, Animator targetAnimator)