Hi Ive been getting this error and i've been stuck on it for a while

JoinRoom failed. Client is on MasterServer (must be Master Server for matchmaking)but not ready for operations (State: PeerCreated). Wait for callback: OnJoinedLobby or OnConnectedToMaster


the code is this and i've searched for a while but can't find the error

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using Photon.Pun;

public class CreateAndJoinRooms : MonoBehaviourPunCallbacks
{
  public InputField createInput;
  public InputField joinInput;

  public void CreateRoom()
  {
    PhotonNetwork.CreateRoom(createInput.text);
  }

  public void JoinRoom()
  {
    PhotonNetwork.JoinRoom(joinInput.text);
  }

  public override void OnJoinedRoom()
  {
    PhotonNetwork.LoadLevel("Game");
  }
}


Answers

  • You can only join a "room" once you are connected to a "lobby", and you can only join a lobby once you are connected to the "master server", often you would use PhotonNetwork.ConnectUsingSettings, once that callback fires OnConnectedToMaster, you can then PhotonNetwork.JoinLobby and then once the OnJoinedLobby callback also fires, you can PhotonNetwork.CreateRoom or JoinRoom etc - one thing to keep in mind is that rooms are only visible for the region they are created in (so if you have player A in EU region and player B in US region but they are both in the same default Lobby, player B will NOT see any rooms created by player A and vice versa), this is cause by default most people use the cloud relay since its already setup, but you CAN optionally use your own server to act as the "master server", because thats an option even with ConnectUsingSettings, you have to wait for the relevant callbacks before you can start creating and joining rooms


    The docs may be able to explain this better as they have code examples as well:

    https://doc.photonengine.com/en-us/pun/current/getting-started/initial-setup

    https://doc.photonengine.com/en-us/pun/current/connection-and-authentication/regions