Joining and Re-joining Lobbies

Options
Hello

I am having a hard time with the following flow...

1) I join a lobby with PhotonNetwork.JoinLobby()
2) PhotonNetwork.InLobby is "true". All good here.
3) I join a room (with either CreateRoom() or JoinRoom())
4) PhotonNetwork.InLobby is "false". I don't know whether this is intended behavior or not... but it's fine. (I'm not sure why joining a room bumps you from a lobby)
5) I leave the room with PhotonNetwork.LeaveRoom();
6) I try to join a lobby again, with PhotonNetwork.JoinLobby()

Step 6 above does not seem to work. I can't seem to join a lobby again. It won't fire "OnJoinedLobby" and PhotonNetwork.InLobby continues to be false.

Whats going on here? Is this supposed to work this way?

Comments

  • JohnTube
    JohnTube ✭✭✭✭✭
    Options
    Hi @Brant,

    Thank you for choosing Photon!

    4) that's expected yes. You can be either in a lobby or in a room or neither. You can't be joined to both at the same time, in fact you need to be on completely different servers for that matter.
    6) when do you try to join a lobby again? after / in which callback? make sure to do it inside or after OnConnectedToMaster.
  • Brant
    Brant
    edited April 2020
    Options
    @JohnTube - Thanks or the response.

    OnConnectedToMaster is called much earlier in the process of things. Before step #1 is when I do things like authenticate to the servers. In other words, by the time I get here, I connected to master several scenes ago.

    Am I misunderstanding something? Would joining rooms/lobbies disconnect me from master?


    To answer your question, I am currently just doing this in a bit of a test loop. It looks something like this (some of this is just pseudo code, just trying to show the flow):
    Start(){ PhotonNetwork.JoinLobby();  } 
    OnJoinedLobby() { 
       PhotonNetwork.InLobby(); // true
       PhotonNetwork.CreateRoom(name of room); 
    } 
    OnJoinedRoom() { 
      PhotonNetwork.InLobby(); // false
      PhotonNetwork.LeaveRoom(); 
    } 
    OnLeftRoom() { 
      PhotonNetwork.InLobby();  // false
      PhotonNetwork.JoinLobby(); // "OnJoinedLobby" never fires again here and "InLobby()" continues to show false
    } 
    
  • Brant
    Options
    @JohnTube You pointed me on the right path! Thank you.

    In re-reviewing documentation, I saw this bit: https://doc-api.photonengine.com/en/pun/v2/class_photon_1_1_pun_1_1_mono_behaviour_pun_callbacks.html#a5109a4e0cc11ef64fe8f22370abe5cb9

    Particularly, the part that reads:
    When leaving a room, the LoadBalancingClient will disconnect the Game Server and connect to the Master Server. This wraps up multiple internal actions.

    Wait for the callback OnConnectedToMaster, before you use lobbies and join or create rooms.

    So, given the flow I outlined above, the corrected version would be:
    Start(){ PhotonNetwork.JoinLobby();  } 
    OnJoinedLobby() { 
       PhotonNetwork.InLobby(); // true
       PhotonNetwork.CreateRoom(name of room); 
    } 
    OnJoinedRoom() { 
      PhotonNetwork.InLobby(); // false
      PhotonNetwork.LeaveRoom(); 
    } 
    OnLeftRoom() { 
      // do nothing here
    } 
    OnConnectedToMaster{
      // this fires AFTER OnLeftRoom()
      PhotonNetwork.JoinLobby(); // "OnJoinedLobby" now fires as expected and "InLobby" evaluates true.
    }
    

    Thanks again for the help!