Home > Mobile >  CreateRoom failed. Client is on MasterServer
CreateRoom failed. Client is on MasterServer

Time:02-24

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/[email protected]/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

CodePudding user response:

You need to use PhotonNetwork.ConnectUsingSettings(); before you can create or join rooms.

Put that in your Start() method of your script.

Read more about it in the "Getting started" part of their documentation: https://doc.photonengine.com/en-us/pun/current/getting-started/pun-intro

CodePudding user response:

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);
    }
}
  • Related