Joining and Re-joining Lobbies
The whole answer can be found below.
Try Our
Documentation
Please check if you can find an answer in our extensive documentation on PUN.
Join Us
on Discord
Meet and talk to our staff and the entire Photon-Community via Discord.
Read More on
Stack Overflow
Find more information on Stack Overflow (for Circle members only).
Joining and Re-joining Lobbies
Brant
2020-04-10 04:07:36
Hello
I am having a hard time with the following flow...
- I join a lobby with PhotonNetwork.JoinLobby()
- PhotonNetwork.InLobby is "true". All good here.
- I join a room (with either CreateRoom() or JoinRoom())
- 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)
- I leave the room with PhotonNetwork.LeaveRoom();
- 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
Hi @Brant,
Thank you for choosing Photon!
- 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.
- when do you try to join a lobby again? after / in which callback? make sure to do it inside or after OnConnectedToMaster.
@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
}
@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!
Back to top