CreateRoom failed. Client is on MasterServer

Viewed 1783

When i trying to create room, nothing happens and there is an error in title. What should I do?

If it is possible, than write what specificly should be replaced.

Full error:

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

UnityEngine.Debug:LogError (object)

Photon.Pun.PhotonNetwork:CreateRoom (string,Photon.Realtime.RoomOptions,Photon.Realtime.TypedLobby,string[]) (at Assets/Photon/PhotonUnityNetworking/Code/PhotonNetwork.cs:1782)

MenuManagerScript:CreateRoom () (at Assets/MenuManagerScript.cs:15)

UnityEngine.EventSystems.EventSystem:Update () (at Library/PackageCache/com.unity.ugui@1.0.0/Runtime/EventSystem/EventSystem.cs:385)

Full code:

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

public class MenuManagerScript : MonoBehaviourPunCallbacks
{
    public InputField createInput;
    public InputField joinInput;
    public void CreateRoom() {
        RoomOptions roomOptions = new RoomOptions();
        roomOptions.MaxPlayers = 4;
        PhotonNetwork.CreateRoom(createInput.text, roomOptions);
    }
    public void JoinRoom() {
        PhotonNetwork.JoinRoom(joinInput.text);
    }
    public override void OnJoinedRoom() {
        PhotonNetwork.LoadLevel("Game");
    }
}
I take code from this video: https://youtu.be/IfP5ChmhVFk?t=485
3 Answers

Here is my code for photon network

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

public class NetworkManager : MonoBehaviourPunCallbacks
{
    public static NetworkManager instance;

    public override void OnConnectedToMaster()
    {
        Debug.Log("Connected to master server");
        CreateRoom("testroom");
    }

    public override void OnCreatedRoom()
    {
        Debug.Log("Created room: " + PhotonNetwork.CurrentRoom.Name);
    }

    void Start()
    {
        Debug.Log(" started");
        PhotonNetwork.ConnectUsingSettings();
    }

    public void CreateRoom(string roomName)
    {
        PhotonNetwork.CreateRoom(roomName);
    }

    public void JoinRoom(string roomName)
    {
        PhotonNetwork.JoinRoom(roomName);
    }

    public void ChangeScene(string sceneName)
    {
        PhotonNetwork.LoadLevel(sceneName);
    }
}

For me the issue was because the default scene is Lobby when you load in, you need to switch to the Loading scene before you load so it can properly connect to Lobby

basically just switch to the Loading scene before you play

You want to connect, before trying to create or join any rooms. PUN contains a very simple script to get you into a random room without much hassle. Check out the ConnectAndJoinRandom component.

Related