Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

Question Photon PUN and Ready Player Me, need help to make it so that player doesn't look the same as client.

Discussion in 'Multiplayer' started by joshuaradec, Jan 4, 2022.

  1. joshuaradec

    joshuaradec

    Joined:
    Jun 14, 2019
    Posts:
    14
    Good day.

    Currently, I am working on an avatar system using Ready Player Me's URL based avatar and Photon, unfortunately at the moment, all loaded avatar will look the same as client's own, making the avatar customisation null and void. I've been trying to figure it out for a month now but to no avail. Previously, this project was worked on by others, they used UMA's avatar system.


    Code (CSharp):
    1. using UnityEngine;
    2. using System;
    3. using System.Collections;
    4. using Wolf3D.ReadyPlayerMe.AvatarSDK;
    5. using Photon.Pun;
    6. using System.IO;
    7. using System.Collections.Generic;
    8.  
    9.  
    10. public class RuntimePref : MonoBehaviourPun
    11. {
    12.     [SerializeField] private PhotonView PV;
    13.     [SerializeField] private bool networkScene;
    14.     [SerializeField] private string AvatarURL;
    15.     public Transform parent;
    16.     public GameObject tistis;
    17.     public bool loadlababi = false;
    18.      public string myurl = "";
    19.     private bool firstTime = false;
    20.  
    21.     public void Start()
    22.     {
    23.         AvatarURL = PlayerPrefs.GetString("URLRPM", "https://d1a370nemizbjq.cloudfront.net/e6aa083e-5e0a-4651-b473-5a24496ca9e2.glb");
    24.         Debug.Log($"Started loading avatar. [{Time.timeSinceLevelLoad:F2}]");
    25.         AvatarLoader avatarLoader = new AvatarLoader();
    26.         tistis.SetActive(false);
    27.         loadlababi = true;
    28.  
    29.  
    30.         Debug.Log("geh");
    31.         if (PV.IsMine)
    32.         {
    33.             Debug.Log("URLRPM");
    34.             photonView.RPC("whaturl", RpcTarget.AllBuffered, PlayerPrefs.GetString("URLRPM"));
    35.         }
    36.      
    37.         if (PlayerPrefs.HasKey("URLRPM"))
    38.             LoadURL();
    39.  
    40.  
    41.         firstTime = true;
    42.  
    43.     }
    44.  
    45.     public void AvatarLoaderHa()
    46.     {
    47.         AvatarLoader avatarLoader = new AvatarLoader();
    48.         avatarLoader.LoadAvatar(AvatarURL, OnAvatarImported, OnAvatarLoaded);
    49.    }
    50.  
    51.     public void LoadURL()
    52.     {
    53.         if (firstTime != null)
    54.  
    55.         if (PV.IsMine)
    56.         {
    57.             myurl = PlayerPrefs.GetString("URLRPM");
    58.             PV.RPC("whatRecipe", RpcTarget.OthersBuffered, myurl);
    59.             Debug.Log("my recipe should be " + myurl)
    60.  
    61.         }
    62.         else if (!networkScene)
    63.         {
    64.             myurl = PlayerPrefs.GetString("URLRPM");
    65.             Debug.Log("my recipe should be " + myurl);
    66.            
    67.         }
    68.  
    69.     }
    70.    
    71.  
    72.     private void Update()
    73.     {
    74.         if (loadlababi == true)
    75.         {
    76.             StartCoroutine(loadAvatarChildren());
    77.         }
    78.     }
    79.  
    80.     private void OnAvatarImported(GameObject avatar)
    81.     {
    82.         Debug.Log($"Avatar imported. [{Time.timeSinceLevelLoad:F2}]");
    83.     }
    84.  
    85.     private void OnAvatarLoaded(GameObject avatar, AvatarMetaData metaData)
    86.     {
    87.         Debug.Log($"Avatar loaded. [{Time.timeSinceLevelLoad:F2}]\n\n{metaData}");
    88.         avatar.transform.SetParent(parent, false);
    89.  
    90.     }
    91.  
    92.     IEnumerator loadAvatarChildren()
    93.     {
    94.         yield return new WaitForSeconds(5.0f);
    95.         tistis.SetActive(true);
    96.     }
    97.  
    98.     [PunRPC]
    99.     void whaturl(string sentUrl)
    100.     {
    101.         myurl = sentUrl;
    102.      
    103.         Debug.Log("my url should be " + myurl);
    104.      
    105.         AvatarLoaderHa();
    106.        
    107.     }
    108.  
    109. }
    110.  
    Any help would be graciously appreciated.
     
  2. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    2,957
    Isn't the URLRPM hard coded in the first place?
    Also, if the avatar url is "per player", I would not keep it in a buffered RPC but instead use a Custom Player Property. Each character can run a script and load the avatar of the PhotonView creator.
     
    lmbarns, joshuaradec and toddkc like this.
  3. joshuaradec

    joshuaradec

    Joined:
    Jun 14, 2019
    Posts:
    14
    Appreciate the input, unfortunately atm I am unfamiliar with that. Any guide on that?
     
  4. joshuaradec

    joshuaradec

    Joined:
    Jun 14, 2019
    Posts:
    14
    also, the URLRPM is made via this script :

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.SceneManagement;
    3.  
    4.  
    5. namespace Wolf3D.ReadyPlayerMe.AvatarSDK
    6. {
    7.     public class WebViewTest : MonoBehaviour
    8.     {
    9.         private GameObject avatar;
    10.  
    11.         [SerializeField] private WebView webView;
    12.         [SerializeField] private GameObject loadingLabel = null;
    13.         [SerializeField] private GameObject displayButton = null;
    14.  
    15.         public void DisplayWebView()
    16.         {
    17.             if(webView == null)
    18.             {
    19.                 webView = FindObjectOfType<WebView>();
    20.             }
    21.             else if (webView.Loaded)
    22.             {
    23.                 webView.SetVisible(true);
    24.             }
    25.             else
    26.             {
    27.                 webView.CreateWebView();
    28.                 webView.OnAvatarCreated = OnAvatarCreated;
    29.             }
    30.         }
    31.  
    32.         // WebView callback for retrieving avatar url
    33.         private void OnAvatarCreated(string url)
    34.         {
    35.             if (avatar) Destroy(avatar);
    36.  
    37.             webView.SetVisible(false);
    38.             loadingLabel.SetActive(true);
    39.             displayButton.SetActive(false);
    40.             PlayerPrefs.SetString("URLRPM", url);
    41.  
    42.             AvatarLoader avatarLoader = new AvatarLoader();
    43.             avatarLoader.LoadAvatar(url, null, OnAvatarImported);
    44.         }
    45.  
    46.         // AvatarLoader callback for retrieving loaded avatar game object
    47.         private void OnAvatarImported(GameObject avatar, AvatarMetaData metaData)
    48.         {
    49.             this.avatar = avatar;
    50.             loadingLabel.SetActive(false);
    51.             displayButton.SetActive(true);
    52.  
    53.             Debug.Log("Loaded");
    54.         }
    55.  
    56.        // public void BackButton()
    57.        // {
    58.             //UIManager.checker = true;
    59.            // SceneManager.LoadScene("New Login");
    60.         //}
    61.  
    62.     }
    63. }
    64.  
    This was modified from Ready Player Me's own system.
     
  5. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    2,957
    I linked to the docs for Custom Properties. Sorry, I don't have a guide to use them for this use case specifically.
     
  6. Xadegamer

    Xadegamer

    Joined:
    Jan 30, 2017
    Posts:
    1
    where you able to solve this issue?
     
  7. teto10sv

    teto10sv

    Joined:
    Aug 31, 2022
    Posts:
    1
    You can trying to figure it out for a month now but to no avai
     
  8. prog12

    prog12

    Joined:
    Nov 4, 2018
    Posts:
    1
    did you solve this issue?