Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Third Party [Photon Pun] Only one player gets loaded into new scene. Why?

Discussion in 'Multiplayer' started by jlorenzi, Jan 15, 2024.

  1. jlorenzi

    jlorenzi

    Joined:
    May 2, 2021
    Posts:
    293
    When the master client walks into the level loader object. It only loads the person who isn't the master client into the new scene. Does anyone know what could cause this?
    Code:
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using Photon.Pun;
    5.  
    6. public class LoadLevel : MonoBehaviour
    7. {
    8.     public string levelName;
    9.  
    10.     private void Start()
    11.     {
    12.         PhotonNetwork.AutomaticallySyncScene = true;
    13.     }
    14.  
    15.     private void OnTriggerEnter(Collider other)
    16.     {
    17.         Debug.Log("Level loaded was triggered");
    18.         if ( other.CompareTag("Player") )
    19.         {
    20.             if ( !PhotonNetwork.IsMasterClient )
    21.             {
    22.                 return;
    23.             }
    24.  
    25.             Debug.Log("Loading new level");
    26.             PhotonNetwork.LoadLevel(levelName);
    27.         }
    28.     }
    29. }
    30.  
     
  2. bergBoys

    bergBoys

    Joined:
    Jun 22, 2023
    Posts:
    2
    I've been having the same problem and I've been trying to look everywhere for the fix If I find out how to fix it I will reply and tell you how to fix it
     
  3. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,076
    I don't see anything obviously incorrect here.
    Any errors on either client?
     
  4. jlorenzi

    jlorenzi

    Joined:
    May 2, 2021
    Posts:
    293
    No errors, but looking at the hierarchy it seems like it is trying to load the level but gets stuck somewhere and gets into an infinite loading session. Maybe it's to do with the fact that it's trying to load the level twice?
    upload_2024-1-15_10-8-5.png
    upload_2024-1-15_10-8-30.png
     

    Attached Files:

  5. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,076
    It should be possible to avoid loading twice. Or is that by design?
    PUN (out of the box) only supports actually changing the level, not re-loading one.
     
  6. jlorenzi

    jlorenzi

    Joined:
    May 2, 2021
    Posts:
    293
    Definitely not by design. I don't know why it was loading twice but I added a debounce timer to prevent it from loading multiple times in the same second and it fixed it. Thanks for your help.
     
    tobiass likes this.