Leaving a room and joining a new random room?
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).
Leaving a room and joining a new random room?
GalacticCyclist
2021-11-11 22:37:49
Hi,
I am trying to leave a room and join a new random room. On my OnLeftRoom() handler, I try calling PhotonNetwork.JoinRandomRoom(newRoomHash) but I get the following error:
JoinRandomRoom failed. Client is on MasterServer (must be Master Server for matchmaking) but not ready for operations (State: Authenticating). Wait for callback: OnJoinedLobby or OnConnectedToMaster.
UnityEngine.Debug:LogError (object)
So by the look of this error, I need to do some handling of the MasterClient, however I am not sure what. The documentation says the following about the LeaveRoom() function which I am calling:
LeaveRoom (bool becomeInactive=true) Leave the current room and return to the Master Server where you can join or create rooms (see remarks)
So based on the above docs, I am attempting to do just that -> Leave the current room and join or create another random room. In my current test, I am the MasterClient as I am the only player. Should I be disconnecting completely? That would not seem to make sense. Please advise the best approach and what I need to handle in regards the master client.
Comments
Hi!, Usually OnLeftRoom is used to clean the user's list when the local user leave the room. For example:
public override void OnLeftRoom()
{
Debug.Log("Exit a Room");
//Destroying the user list
//PlayersDictionary is a list of players
foreach(GameObject ObjectPlayer in PlayersDictionary.Values)
{
Destroy(ObjectPlayer);
}
PlayersDictionary.Clear();
PlayersDictionary = null;
}
After you leave a room the method OnConnectedToMaster is called. So I suggest you to create another method to Join a random room after you connected to master.
public void JoinRandomRoom()
{
PhotonNetwork.JoinRandomOrCreateRoom();
}
So don't use PhotonNetwork.JoinRandomOrCreateRoom() in OnLeftRoom method
Back to top