Search Unity

Third Party Photon PUN2 - Meshes downloaded at runtime not visible

Discussion in 'Multiplayer' started by LuckyLadyGames, Jul 13, 2022.

  1. LuckyLadyGames

    LuckyLadyGames

    Joined:
    Mar 30, 2022
    Posts:
    8
    Hello, I'm using PUN2 for a multiplayer game, and I'm having an issue that players can't see other players meshes. I'm assuming this is occurring because these meshes get loaded in at runtime, and aren't stored in the resources folder. Is there any way for other players to see meshes downloaded at runtime?

    Right now, in my resources folder, I have a player prefab that basically just contains an animator, character controller, Photon View, Photon Transform View, and Photon Animator view. This prefab gets loaded in via a PhotonNetwork.Instantiate() call, and after instantiation, a call is made to download a player mesh via ReadyPlayerMe. This mesh then gets parented to the player prefab, and the player character is good to go, except theses meshes are only displayed on player's own machines. For other players, their player prefabs get imported no problem, but their meshes don't get downloaded and attached.

    Is there any way to do this? To display character meshes that doesn't originate from a prefab in the resources folder, and get downloaded after instantiation? I've attached a screenshot that hopefully illustrates this. Both characters are there, one character mesh is missing. I have a sphere right now to help me see where the character is located.

    Thanks!

    PUN2-RPM.png
     
  2. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,066
    It is definitely possible to show meshes loaded from somewhere else. Instantiating a "blank" character sounds like a useful approach, too.
    If others don't download and attach the correct mesh, make sure the scripts you expect to run (to download and attach) are actually running. In this specific case, don't run them only on the controlling client (which is frequently done by checking IsMine).
     
  3. LuckyLadyGames

    LuckyLadyGames

    Joined:
    Mar 30, 2022
    Posts:
    8
    Thanks Tobiass,

    What's curious is I don't even have any isMine checks in there yet. Everything works great with instantiating the prefab from resources, but the downloaded mesh then only gets attached to the users own player. No other player meshes are visible/attached. Here's the script I'm running if this helps clarify anything...

    Code (CSharp):
    1. using UnityEngine;
    2. using ReadyPlayerMe;
    3. using Photon.Pun;
    4.  
    5. public class GameManager : MonoBehaviour
    6. {
    7.     [SerializeField] private GameObject playerPrefab;
    8.     [SerializeField] private Transform playerSpawnPosition;
    9.     [SerializeField] private string avatarUrl;
    10.  
    11.     private GameObject playerClone;
    12.  
    13.     private void Start()
    14.     {
    15.         playerClone = PhotonNetwork.Instantiate(playerPrefab.name, playerSpawnPosition.position, playerSpawnPosition.rotation);
    16.         LoadAvatar();
    17.     }
    18.  
    19.     private void LoadAvatar()
    20.     {
    21.         Debug.Log($"Started loading avatar. [{Time.timeSinceLevelLoad:F2}]");
    22.  
    23.         var avatarLoader = new AvatarLoader();
    24.         avatarLoader.OnCompleted += (sender, args) =>
    25.         {
    26.             Debug.Log($"Loaded avatar. [{Time.timeSinceLevelLoad:F2}]");
    27.             Debug.Log($"{args.Avatar.gameObject} is imported!");
    28.  
    29.             var avatar = args.Avatar.gameObject;
    30.             avatar.transform.SetParent(playerClone.transform);
    31.             avatar.transform.localPosition = Vector3.zero;
    32.  
    33.             var animator = avatar.GetComponent<Animator>();
    34.             if (animator) Destroy(animator);
    35.  
    36.             Animator anim = playerClone.GetComponent<Animator>();
    37.  
    38.             if (anim)
    39.             {
    40.                 anim.Rebind();
    41.                 anim.Update(0f);
    42.             }
    43.         };
    44.  
    45.         avatarLoader.OnFailed += (sender, args) =>
    46.         {
    47.             print("FAIL");
    48.             Debug.Log(args.Type);
    49.         };
    50.  
    51.         avatarLoader.LoadAvatar(avatarUrl);
    52.     }
    53.  
    54. }
    Here's a screenshot of what's visible on each player's screen...

    pun2-screenshot.png

    Let me know if there's something I'm missing. I'd love to get this working, but not sure what to do.


     
  4. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,066
    Maybe check if the mesh gets assigned to the correct "base"? Do you load different meshes already? Would you notice if the other player's mesh gets assigned to your instance?
     
  5. erikvc

    erikvc

    Joined:
    Jul 17, 2014
    Posts:
    1
    I have this same problem, I still haven't found a solution!
     
  6. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,066
    Same questions as above.
     
  7. gaurav12patidar

    gaurav12patidar

    Joined:
    Jul 4, 2022
    Posts:
    1
    I cant even create a prefab:
    I load ReadyPlayerMe Avatar from tools menu
    drag and drop avatar to prefabs
    but when i try to see that my prefab is created correctly, it is just invisible object.
     
  8. naveenvade

    naveenvade

    Joined:
    Jul 15, 2022
    Posts:
    1
    Has anyone found the solution for this issue for making avatarloader to load a avatar at runtime and make it visible to other players in the network?
     
  9. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,066
    Each client has to load the avatar. To be able to load a specific avatar for someone else, you need to share the configuration for the avatar. If each user sets the own avatar's code as a Custom Property, this is shared and everyone else can load that avatar, then apply it to the character you control (it's just a visual change, the network structure which syncs avatars is not changing when you replace the avatar look).