Hey!
What is the best way to sync those changes over the server to other players? So that they can see the new clothes the player wears. I use the in app avatar creator instead of web based
I think this is the sollution but there is no Mirror package. Is it possible in Mirror? Setup Multiplayer | Ready Player Me
Anyone that can help me with this problem?
Hello @DutchRose, and welcome to forums!
In the same page you shared, we mention this:
After loading the User-Avatar, you’ll be returned a GameObject from the AvatarManager
. Do not use this game object, instead do a mesh transfer and destroy the game object. You can use the AvatarMeshHelper.TransferMesh(...)
from the SDK. Check out how it’s done in the packages for both, Photon and Unity Netcode below.
So, regardless of the multiplayer tool you use, you should be able to use the AvatarMeshHelper.TransferMesh(...)
to sync the avatar appearance.
Hey @Amel_RPM
I tried that but then I get this error:
{"type":"NotFoundError","status":404,"message":"Not Found"}
GET https://models.readyplayer.me/67fd0c6f6026f5144d792c70.json
This is how I do it:
Below is the method that is fired when the player is choosing assets from the in app character creator:
private void TransferAvatarData(string id, AvatarMetadata metadata)
{
var avatarData = AvatarComponentReferences.Instance.AvatarData;
avatarData.AvatarId = id;
avatarData.AvatarMetadata = metadata;
var player = NetworkClient.connection.identity;
player.GetComponent<AvatarSyncFromData>().SetAvatarId(avatarData.AvatarId);
}
And on the NetworkedPlayer I have this script:
using Mirror;
using ReadyPlayerMe.Core;
using UnityEngine;
public class AvatarSyncFromData : NetworkBehaviour
{
[Header("Assigned Avatar Rig")]
public GameObject avatar;
[Header("Avatar Configuration (RPM SD support)")]
[SerializeField] private AvatarConfig avatarConfig;
[Header("Synced Properties")]
[SyncVar(hook = nameof(OnAvatarIdChanged))]
public string avatarModelID;
private AvatarObjectLoader _avatarObjectLoader;
private void OnEnable()
{
_avatarObjectLoader = new AvatarObjectLoader(avatarConfig);
_avatarObjectLoader.OnCompleted += OnAvatarLoaded;
_avatarObjectLoader.OnFailed += OnAvatarLoadFailed;
}
private void OnDisable()
{
_avatarObjectLoader.OnCompleted -= OnAvatarLoaded;
_avatarObjectLoader.OnFailed -= OnAvatarLoadFailed;
}
public override void OnStartLocalPlayer()
{
if (!string.IsNullOrEmpty(avatarModelID))
{
CmdSetAvatarModelId(avatarModelID);
}
}
public void SetAvatarId(string newId)
{
CmdSetAvatarModelId(newId);
}
[Command]
private void CmdSetAvatarModelId(string newId)
{
avatarModelID = newId;
}
private void OnAvatarIdChanged(string oldId, string newId)
{
LoadRpmAvatar(newId);
}
private void LoadRpmAvatar(string id)
{
Debug.Log($"[NetworkCharacter] Loading avatar with ID: {id}");
_avatarObjectLoader.LoadAvatar(id);
}
private void OnAvatarLoaded(object sender, CompletionEventArgs e)
{
Debug.Log("[NetworkCharacter] Avatar loaded successfully.");
GameObject downloadedAvatar = e.Avatar;
AvatarMeshHelper.TransferMesh(downloadedAvatar, avatar);
Destroy(downloadedAvatar);
}
private void OnAvatarLoadFailed(object sender, FailureEventArgs e)
{
Debug.LogError($"[NetworkCharacter] Avatar download failed: {e.Message}");
}
}
What am I doing wrong here?
Maybe good to know that i’m currently using guests accounts for my app