Forum Discussion

🚨 This forum is archived and read-only. To submit a forum post, please visit our new Developer Forum. 🚨
Gabo.Andres's avatar
Gabo.Andres
Explorer
3 years ago

Any guide for meta avatars network working with photon

I want to make a multiplayer expirience in VR with unity and I want to use de meta avatars SDK but I can't find a guide on how to do it, and I think is because I don't have to much expirience in networking but the documentation doesn't help me. I can use them locally very easily but for multiplayer I have no idea on how to implement this.

Just to add that is no like I don't know anything about multiplayer, I actually have a VR multiplayer proyect and it works perfect, is just that I want to have the meta avatars instead of custom made avatars because is so much work to do my own avatar system.

 

Hope sombody can help me with a guide or something to study how to do it! :c

2 Replies

Replies have been turned off for this discussion
  • Here is a script I created for Meta Avatars + Photon Fusion, hope it helps:
     

     

    using Fusion;
    using UnityEngine;
    using System.Collections.Generic;
    using Oculus.Avatar2;
    
    public class NetworkAvatar : NetworkBehaviour
    {
        [SerializeField] public OvrAvatarEntity Avatar;
        [SerializeField] public bool isLocal = true;
        private float cycleStartTime_Local = 0;
        private float intervalToSendData_Local = 0.08f;
        private List<byte[]> streamedDataList_Remote = new List<byte[]>();
    
        void LateUpdate()
        {
            if (isLocal) LocalLateUpdate();
        }
        void Update()
        {
            if (!isLocal) RemoteUpdate();
        }
    
    #region Local Functions
        private void LocalLateUpdate()
        {
            float elapsedTime = Time.time - cycleStartTime_Local;
            if (elapsedTime <= intervalToSendData_Local) return;
    
            RecordAndSendStreamData();
            cycleStartTime_Local = Time.time;
        }
    
        void RecordAndSendStreamData()
        {
            byte[] bytes = Avatar.RecordStreamData(Avatar.activeStreamLod);
            if (bytes == null) return;
    
            RPC_ReceiveStreamData(bytes);
        }
    #endregion
    
    #region Remote Functions
        [Rpc(RpcSources.All, RpcTargets.All, InvokeLocal = false)]
        public void RPC_ReceiveStreamData(byte[] bytes)
        {
            streamedDataList_Remote.Add(bytes);
        }
        
        private void RemoteUpdate()
        {
            if (streamedDataList_Remote.Count == 0) return;
    
            byte[] firstBytesInList = streamedDataList_Remote[0];
            if (firstBytesInList != null)
            {
                Avatar.ApplyStreamData(firstBytesInList);
            }
            streamedDataList_Remote.RemoveAt(0);
        }
    #endregion
    }