Avatar spawning away from the actual avatar placeholder

Hey! Guys I am quite new to building on ReadyPlayerMe and I am currently working on a multiplayer based collaborative VR application where I am using ReadyPlayerMe’s Half Body Avatars

After a lot of hit and trials I finally got half body avatars to work but the problem now is the avatar after being downloaded is spawning way forward to the position of the placeholder.

So lets say the placeholder is at the center then that avatar is being loaded at least 5 to 10 units away from the placeholder even though the transfer mesh is working and is replacing the placeholder with the halfbody avatar.

I am really stuck on this and causing a lot of delays for so please it would be great if anyone could help me out on this.



image

This is the code

#if PHOTON_UNITY_NETWORKING && READY_PLAYER_ME
using Photon.Pun;
using UnityEngine;
using ReadyPlayerMe.Core;

namespace ReadyPlayerMe.PhotonSupport
{
    /// <summary>
    ///     Used on Ready Player Me 
    /// </summary>
    [RequireComponent(typeof(PhotonView))]
    public class NetworkPlayer : MonoBehaviour
    {
        private const string SET_PLAYER_METHOD = "SetPlayer";
        [SerializeField] private AvatarConfig config;
        [SerializeField] private SkinnedMeshRenderer m_SkinnedMeshRenderer;

        private PhotonView photonView;

        private Transform leftEye;
        private Transform rightEye;

        private void Awake()
        {
            photonView = GetComponent<PhotonView>();

            leftEye = AvatarBoneHelper.GetLeftEyeBone(transform, false);
            rightEye = AvatarBoneHelper.GetRightEyeBone(transform, false);
        }

        /// <summary>
        ///     Calls PunRPC with the avatar URL as paramater to load the local and remote avatars.
        /// </summary>
        /// <param name="url">Avatar URL</param>
        public void LoadAvatar(string url)
        {
            photonView.RPC(SET_PLAYER_METHOD, RpcTarget.AllBuffered, url);
        }

        [PunRPC]
        private void SetPlayer(string incomingUrl)
        {
            AvatarObjectLoader loader = new AvatarObjectLoader();
            loader.AvatarConfig = config;
            loader.LoadAvatar(incomingUrl);
            loader.OnCompleted += (sender, args) =>
            {
                leftEye.transform.localPosition = AvatarBoneHelper.GetLeftEyeBone(args.Avatar.transform, false).localPosition;
                rightEye.transform.localPosition = AvatarBoneHelper.GetRightEyeBone(args.Avatar.transform, false).localPosition;
                //Destroy(gameObject);
                Destroy(args.Avatar);
                AvatarMeshHelper.TransferMesh(args.Avatar, gameObject);
            };
        }

    }
}
#endif

Hi @Priyanshu

There seem to be a few issues with the code you provided.

First, you should call Destroy AFTER avatar you run TransferMesh.
The code positioning the eyes shouldn’t be necessary at all, but if you really want to do it it should be done after setting the root position and transferring the mesh.

As for the position thing, you could try setting the position of args. Avatar to match the gameobjects position before running transfer mesh.

EG:

args.Avatar.transform.position = gameObject.transform.position
args.Avatar.transform.rotation= gameObject.transform.rotation

                
AvatarMeshHelper.TransferMesh(args.Avatar, gameObject);


leftEye.transform.localPosition = AvatarBoneHelper.GetLeftEyeBone(args.Avatar.transform, false).localPosition;
                rightEye.transform.localPosition = AvatarBoneHelper.GetRightEyeBone(args.Avatar.transform, false).localPosition;

Destroy(args.Avatar);
1 Like

This worked really well! Thanks for the solution :slight_smile: