Search Unity

Third Party PhotonNetwork.CurrentRoom retuns null after changing scene

Discussion in 'Multiplayer' started by Clashman, May 12, 2021.

  1. Clashman

    Clashman

    Joined:
    Feb 18, 2019
    Posts:
    53
    Hi ! I really need your help... I made a scene called "Waiting Room". I want all players who joined a room to go in my scene. I have to change scene after joining room but in the new scene. However, after changing my scene, my PhotonNetwork.MasterClient is null and PhotonNetwork.CurrentRoom.Players is null too. What can I do to resolve the problem ?

    Thanks a lot for answers.
     
  2. toddkc

    toddkc

    Joined:
    Nov 20, 2016
    Posts:
    207
    The only way that would happen is if you were not only changing the scene but also leaving the room. Show some code.
     
  3. Clashman

    Clashman

    Joined:
    Feb 18, 2019
    Posts:
    53
    This is my code where I call Photon.NetworkCurrentRoom.Players, this function is called in Update() :

    Code (CSharp):
    1. private void GetCurrentRoomPlayers()
    2.     {
    3.         foreach (KeyValuePair<int, Player> PlayerInfo in PhotonNetwork.CurrentRoom.Players)
    4.         {
    5.             bool AlreadyInList = false;
    6.  
    7.             foreach (PlayerListing ShowedListing in _listings)
    8.             {
    9.                 ShowedListing.GetComponent<RawImage>().texture = Resources.Load<Texture2D>("Textures/Sprites/GUI/Icons/Player" + ShowedListing.ID);
    10.  
    11.                 if (ShowedListing.Player == PlayerInfo.Value)
    12.                 {
    13.                     AlreadyInList = true;
    14.  
    15.                     if (ShowedListing.IsReady == true)
    16.                     {
    17.                         ReadyPlayers[ShowedListing.ID] = true;
    18.                         ShowedListing.ReadyIcon().transform.localScale = new Vector3(1, 1, 1);
    19.                     }
    20.                     break;
    21.                 }
    22.                  
    23.             }
    24.  
    25.             if((!AlreadyInList))
    26.             {
    27.                 AddPlayerListing(PlayerInfo);
    28.             }
    29.         }
    30.     }
     
  4. toddkc

    toddkc

    Joined:
    Nov 20, 2016
    Posts:
    207
    None of that really helps. Maybe add a line
    if (!PhotonNetwork.InRoom) return; 
    in your update also so this code won't run unless you are in a room?

    Nothing in that snippet would be responsible for your master client check and players being null though.
     
    aadikhan859 likes this.
  5. Clashman

    Clashman

    Joined:
    Feb 18, 2019
    Posts:
    53
    Hi !
    I resolved my problem... I changed scene before enetring in a room, that's why my room's information returned null.
     
  6. aadikhan859

    aadikhan859

    Joined:
    Jun 21, 2020
    Posts:
    1
    Damn, This helped me today, thank you Bro.
    It helped me in 2022.
     
    toddkc likes this.