Return to lobby after leaving game
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).
Return to lobby after leaving game
ScottS
2017-07-21 12:55:53
Hello,
I'm trying to figure out how to return to a lobby after leaving a game.
My understanding is that when you Join a room, you leave the lobby, leave the master server, and join a room on a game server. So when you leave that room, you are no longer in a lobby and you are connected to a game server so you can't call JoinLobby.
To return to the lobby do I have to disconnect from photon, reconnect, and join the lobby?
Thank you for your time.
Comments
Hi @ScottS,
When you leave the room you automatically disconnect from the Game Server and connect to the Master Server.
If you enabled auto join lobby then you will be joined to the lobby.
Thank you for your help!
When OnLeftRoom()
is called, I am not yet on the master server. So I start a coroutine like this:
while (PhotonNetwork.Server != ServerConnection.MasterServer || PhotonNetwork.connectionStateDetailed != ClientState.ConnectedToMaster) {
yield return null;
}
ConnectToLobby();
Which gets the job done, but I'm wondering if there is some other callback that I can use? OnConnectedToMaster()
isn't called when leaving a room.
If you enable "Auto Join Lobby" then
OnJoinedLobby
will be triggered instead of OnConnectedToMaster
Otherwise, if "Auto Join Lobby" is disabled
OnConnectedToMaster
is connected.
So you do not need the coroutine in OnLeftRoom
to manually rejoin lobby.
Just wait for OnJoinedLobby
.
I believe I need to have AutoJoinLobby off so I can join a specific lobby. (We're leaning towards using a SQL lobby) When you LeaveRoom
you're technically going back to master but OnConnectedToMaster
isn't called. Assuming you have AutoJoinLobby off, is there any way to determine when you've returned to the master server so you can join a lobby again?
Maybe you are switching scenes and the callback call is lost during the transition.
Can you try implement all connection callbacks from IPunCallbacks
(just get the signature from there and add methods to a MonoBehaviour
in the scene or implement interface if you want)
Vallekralle
2023-03-27 20:47:43
Hello JohnTube and all the other programmers :),
I wanted to ask you how to implement (maybe via script) automatic connection to the lobby instead of the master server? I didn't find a solution for this problem and I am very new to photon...
I hope for a answer soon :)
Vallekralle
Edit:
I found my problem! I tried to join a lobby after Leaving a room immediately (in the "OnLeftRoom"-method). That is a mistake because the client didn't even made it to the point to connect to the master server again. So I had to write the "JoinLobby"-method in the "OnConnectedToMaster"-method. I think that can happen often, if people try to connect their game to the server in one scene and join a lobby in another...
I hope I can help some other lost soul. Have a nice week from germany :),
Vallekralle
Back to top