JoinRandomRoom failed. Client is on GameServer (must be Master Server for matchmaking) and ready

I would really appreciate it if you guys could help. I think it has something to do with the callbacks but I am not sure what exactly.
using UnityEngine;
using System.Collections;
using Photon.Pun;
using UnityEngine.UI;
using Photon.Realtime;
using UnityEngine.SceneManagement;

public class NetworkConnectionManager : MonoBehaviourPunCallbacks {

 public Button BtnConnectMaster;
 public Button BtnConnectRoom;
 public bool TriesToConnectToMaster;
 public bool TriesToConnectToRoom;
 // Use this for initialization
 void Start()
 {
     TriesToConnectToMaster = false;
     TriesToConnectToRoom = false;
 }
 // Update is called once per frame
 void Update()
 {
     BtnConnectMaster.gameObject.SetActive(!PhotonNetwork.IsConnected && !TriesToConnectToMaster);
     BtnConnectRoom.gameObject.SetActive(PhotonNetwork.IsConnected && !TriesToConnectToMaster && !TriesToConnectToRoom);
 }
 public void OnClickConnectToMaster()
 {
     //Settings (all optional and only for tutorial purpose)
     PhotonNetwork.OfflineMode = false;           //true would "fake" an online connection
     PhotonNetwork.NickName = "PlayerName";       //to set a player name
     PhotonNetwork.AutomaticallySyncScene = true; //to call PhotonNetwork.LoadLevel()
     PhotonNetwork.GameVersion = "v1";            //only people with the same game version can play together
     TriesToConnectToMaster = true;
     //PhotonNetwork.ConnectToMaster(ip,port,appid); //manual connection
     PhotonNetwork.ConnectUsingSettings();           //automatic connection based on the config file in Photon/PhotonUnityNetworking/Resources/PhotonServerSettings.asset
 }
 public override void OnConnectedToMaster()
 {
     base.OnConnectedToMaster();
     TriesToConnectToMaster = false;
     Debug.Log("Connected to Master!");
 }
 public override void OnDisconnected(DisconnectCause cause)
 {
     base.OnDisconnected(cause);
     TriesToConnectToMaster = false;
     TriesToConnectToRoom = false;
     Debug.Log(cause);
 }
 public void OnClickConnectToRoom()
 {
     if (!PhotonNetwork.IsConnected)
         return;
     TriesToConnectToRoom = true;
     //PhotonNetwork.CreateRoom("Peter's Game 1"); //Create a specific Room - Error: OnCreateRoomFailed
     //PhotonNetwork.JoinRoom("Peter's Game 1");   //Join a specific Room   - Error: OnJoinRoomFailed  
     PhotonNetwork.JoinRandomRoom();               //Join a random Room     - Error: OnJoinRandomRoomFailed  
 }
 public override void OnJoinRandomFailed(short returnCode, string message)
 {
     base.OnJoinRandomFailed(returnCode, message);
     //no room available
     //create a room (null as a name means "does not matter")
     PhotonNetwork.CreateRoom(null, new RoomOptions { MaxPlayers = 20 });
 }
 public override void OnCreateRoomFailed(short returnCode, string message)
 {
     base.OnCreateRoomFailed(returnCode, message);
     Debug.Log(message);
     base.OnCreateRoomFailed(returnCode, message);
     TriesToConnectToRoom = false;
 }
 public override void OnJoinedRoom()
 {
     base.OnJoinedRoom();
     TriesToConnectToRoom = false;
     Debug.Log("Master: " + PhotonNetwork.IsMasterClient + " | Players In Room: " + PhotonNetwork.CurrentRoom.PlayerCount + " | RoomName: " + PhotonNetwork.CurrentRoom.Name);
     SceneManager.LoadScene("Network");
 }
}

Comments

  • JohnTube
    JohnTube ✭✭✭✭✭
    Hi @ECTheHunter,

    Thank you for choosing Photon!

    Like the error message says: in order to call JoinRandomRoom you need to be connected to Master Server, which means you need to be outside of rooms.
    So it looks like you try to join a random room while still joined to one.
    What you need to do is leave the room you are currently joined to, wait until you're connected to Master Server using the proper callback and then you can try to join another random room.
  • thanks
  • It can happen if you double click and meanwhile you are already in the room.
  • So the room was created successfully? And you click the create button again to report an error?
  • I found a tutorial on the Internet, and when I was doing the UI for displaying the room list, I double-clicked the Create Room button to report this error, and the list did not produce a room prefab, but it can. I don’t know what to do. Any hints thanks
  • So the project progress is stuck