- Home /
CreateRoom failed.
I'm trying to create a room, but I'm having an error. Where is the problem?
using Photon.Pun;
using Photon.Realtime;
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
public class Connect : MonoBehaviourPunCallbacks
{
[SerializeField] private GameObject connectingPanel;
[SerializeField] private GameObject createRoomPanel;
[SerializeField] private GameObject startGamePanel;
[SerializeField] private GameObject adversaryPanel;
[SerializeField] private TextMeshProUGUI mainServerText;
[SerializeField] private TextMeshProUGUI mainUserText;
[SerializeField] private TextMeshProUGUI otherServerText;
[SerializeField] private TextMeshProUGUI otherUserText;
[SerializeField] private TextMeshProUGUI infoServerText;
private bool isConnecting = false;
private const string gameVersion = "0.1";
private const int maxPlayersPerRoom = 2;
[SerializeField] int correntNumber = 0;
public void CreateServer()
{
createRoomPanel.SetActive(false);
connectingPanel.SetActive(true);
isConnecting = true;
PhotonNetwork.ConnectUsingSettings(gameVersion);
CreateARoom();
}
public void CreateARoom()
{
RoomOptions roomOptions = new RoomOptions();
roomOptions.IsVisible = true;
roomOptions.MaxPlayers = 2;
PhotonNetwork.CreateRoom(mainServerText.text, roomOptions, TypedLobby.Default);
correntNumber = 1;
}
public void JoinARoom()
{
PhotonNetwork.JoinRoom(mainServerText.text);
correntNumber = 2;
}
public override void OnJoinedRoom()
{
int playerCount = PhotonNetwork.CurrentRoom.PlayerCount;
Debug.Log(playerCount.ToString());
if (playerCount != maxPlayersPerRoom)
{
infoServerText.text = "Waiting for the opponent...";
}
else
{
infoServerText.text = "You are connected!";
if (correntNumber == 1)
{
connectingPanel.SetActive(false);
startGamePanel.SetActive(true);
}
else if (correntNumber == 2)
{
connectingPanel.SetActive(false);
adversaryPanel.SetActive(true);
}
}
}
}
Erro: CreateRoom failed. Client is on MasterServer (must be Master Server for matchmaking)but not ready for operations (State: ConnectingToNameServer). Wait for callback: OnJoinedLobby or OnConnectedToMaster.
Answer by Captain_Pineapple · Feb 02, 2020 at 07:36 PM
The problem is that you have to wait for photon to acutally connect to the cloud service before you can actually open a room.
So there is a callback in the interface IConnectionCallbacks called OnConnectedToMaster which will be your point where you can start joining and/or opening rooms. You are just doing stuff too early.
Your answer
![](https://koobas.hobune.stream/wayback/20220612222422im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Photon Cloud Networking: OnPhotonSerializeView Not Firing 9 Answers
Photon Unity Networking (Viking Demo) Error: Argument is out of range. 1 Answer
Update position via state syncronization results in weird movement. 0 Answers
Bullet Collision in Networking Game. 0 Answers
"Photon Networking" option not appearing under "Add Component" 1 Answer