JoinRandomRoom Failed

Options
I know, this problem is already been asked by many people, but it didn't work well for me. I got this error when I'm making a room for a player. Here's my code

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


public class LaunchManager : MonoBehaviourPunCallbacks
{
    public GameObject EnterGamePanel;
    public GameObject ConnectionStatusPanel;
    public GameObject LobbyPanel;


    #region Unity Methods

    // Start is called before the first frame update
    void Start()
    {
        EnterGamePanel.SetActive(true);
        ConnectionStatusPanel.SetActive(false);
        LobbyPanel.SetActive(false);
    }

    // Update is called once per frame
    void Update()
    {
        
    }

    #endregion


    #region Public Methods

    public void ConnectToPhotonServer()
    {
        if (!PhotonNetwork.IsConnected)
        {
            PhotonNetwork.ConnectUsingSettings();
            ConnectionStatusPanel.SetActive(true);
            EnterGamePanel.SetActive(false);
        }

    }

    public void JoinRandomRoom()
    {
        PhotonNetwork.JoinRandomRoom();
    }

    #endregion


    #region Photon Callbacks

    public override void OnConnectedToMaster()
    {
        Debug.Log(PhotonNetwork.NickName+ " Connected to Photon Server!");
        LobbyPanel.SetActive(true);
        ConnectionStatusPanel.SetActive(false);
    }

    public override void OnConnected()
    {
        Debug.Log("Connected to Internet!");
    }

    public override void OnJoinRandomFailed(short returnCode, string message)
    {
        base.OnJoinRandomFailed(returnCode, message);
        Debug.Log(message);
        CreateAndJoinRoom();
    }

    public override void OnJoinedLobby()
    {
        Debug.Log(PhotonNetwork.NickName + " joined to " + PhotonNetwork.CurrentRoom.Name);
    }

    #endregion


    #region Private Methods

    void CreateAndJoinRoom()
    { 
        string randomRoomName = "Room";
        RoomOptions roomOptions = new RoomOptions();
        roomOptions.IsOpen = true;
        roomOptions.IsVisible = true;
        roomOptions.MaxPlayers = 20;

        PhotonNetwork.CreateRoom(randomRoomName, roomOptions);

    }

    #endregion
}

Comments

  • JohnTube
    JohnTube ✭✭✭✭✭
    edited January 2020
    Options
    Hi @VinzYT,

    Thank you for choosing Photon!

    In your question:
    - it's not clear what error you are referring to, if it's the one in the discussion title, I'm not sure which line in the code is this logged from. The error message you probably refer to and should see is "No match found", in OnJoinRandomFailed.
    - since "this problem is already been asked by many people" why create a new discussion? why not use an old one? Could you read or reread this?
    - it's not clear in the question what "didn't work well" for you. JoinRandomRoom either results in a match found and joining that room or No Match Found and you decide after that what to do: change filters or create a new room.
    - it's not clear what PUN version you use, I guessed from the code it's PUN 2. Which PUN2 version is not mentioned, while it's not needed here, it's always good to provide context and info about environment used.
    - in the code snippet, it's not clear where you call JoinRandomRoom.
    - the code snippet is long and contains things irrelevant to the question.
    - 20 players per room could be too many