0
\$\begingroup\$

I am using PUN2 for my game and I am using the OnRoomListUpdate() function to sync my UI with the rooms that are available to players when they are in the lobby. The room lists come back from Photon just fine until I switch regions. If I switch regions and rejoin the lobby, I get the OnRoomListUpdate() event but no rooms are handed back for that region when I know I have rooms open. Below is the code I have for switching regions:

public void ConnectToRegion(string region)
{
    PhotonNetwork.Disconnect();
    PhotonNetwork.PhotonServerSettings.AppSettings.FixedRegion = region;

    if (!PhotonNetwork.ConnectUsingSettings())
    {
        Debug.LogError("Unable to connect.");
    }
    else
    {
        PhotonNetwork.JoinLobby();
        currentRegionText.text = $"Current region: {region}";
    }
}
\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

I haven't tested myself, but what's sticking out to me is that you're attempting to join lobby right away after calling ConnectUsingSettings, which has some asynchronous work to do. In my project I call JoinLobby after receiving the OnConnectedToMaster callback. So perhaps you're just trying to join the lobby too soon?

EDIT: The disconnect is asynchronous as well. I just needed to put something together myself so here is something you can do (I used the connection callbacks in mine but coroutines should work too, as below). I also used "ConnectToRegion" so that I don't mess with server settings. This works for me, I'm seeing rooms from the selected region.


   public void SwitchToRegion(string region)
   {
      StartCoroutine(SwitchToRegionCoroutine(region));
   }

   IEnumerator SwitchToRegionCoroutine(string region)
   {
      PhotonNetwork.Disconnect();
      yield return new WaitWhile(() => { return PhotonNetwork.IsConnected; });
      PhotonNetwork.ConnectToRegion(region);
      yield return new WaitUntil(() => { return PhotonNetwork.IsConnected; });
      PhotonNetwork.JoinLobby();
   }
\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .