Photon's PUN 2 Error

I have a problem here with Photon’s PUN 2. Sometimes It works, but other times it doesn’t. Since the last 2 weeks it isn’t working that fine. Before it were better, I joined to the master, and then, to the lobby and It allowed me to list the rooms and join them without any problem. Now, I haven’t changed that code that much, I only changed it after the errors started. Now, sometimes it joins a match, but another it doesn’t, showing the following error:

JoinRandomRoom failed. Client is not on Master Server or not yet ready to call operations. Wait for callback: OnJoinedLobby or OnConnectedToMaster.

I only have 2 devices to test my online with PUN, but, even if I created a room is not working anymore, it just seems like works randomly. Here’s my code if you want to check it:
Code (CSharp):

  • void Start()
  • {
  • PhotonNetwork.ConnectUsingSettings();
  • }
    • // Update is called once per frame
  • void Update()
  • {
    • }
  • public override void OnJoinedLobby()
  • {
  • // /* print(“Connected to lobby”)*/;
    • }
  • public override void OnConnectedToMaster()
  • {
  • //This shows a popup to let know the player that is connected
  • //PhotonNetwork.JoinLobby();
  • base.OnJoinedLobby();
  • GameObject.Find(“IWifi”).SetActive(false);
  • print(“Puga”);
  • StatePScript.IsShow = true;
  • Connected = true;
  • GameObject.Find(“IOk”).GetComponent().color = Color.white;
  • print("IOKS Value is " + IOKS.Show);
  • GameObject.Find(“StatusText”).GetComponent().text = “Connected!”;
  • GameObject.Find(“StatusText”).GetComponent().color = Color.green;
  • A.Play();
  • GameObject.Find(“StatePanel”).GetComponent().SetBool(“Show”, false);
  • IOKS.Show = false;
  • GameObject.Find(“IOk”).GetComponent().color = new Color(0, 0, 0, 0);
  • Connected = false;
  • StatePScript.IsShow = false;
  • }

This is a timing issue, which you can control with the way you test. Connecting to the Photon Cloud is a “process” and if you call operations (like Join) before the process is done, you get this sort of error.
The client’s logic can be improved to wait for the callback OnConnectedToMaster, before it enables the “find game” button (or whatever you use to create/join rooms).

The minimal logic to get into a room is in ConnectAndJoinRandom.cs.