On part four of the official PUN tutorial, I get the error "JoinRandomRoom/CreateRoom failed."

Options
I am on part four of the PUN tutorial on the official website. As far as I can tell, I have written all my code correctly. However, when I press the "Play" button, this happens (click the link to view this on google drive): https://drive.google.com/open?id=1x_HqMstBYaD3fTmtyDHpNKkltQrVkZcV.

Here is my code for the Launcher script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Photon.Pun;
using Photon.Realtime;

public class Launcher : MonoBehaviourPunCallbacks {

    string gameVersion = "0.1a";

    [SerializeField]
    byte maxPlayersPerRoom = 4;

    private void Awake() {

        PhotonNetwork.AutomaticallySyncScene = true;
    }


    private void Start() {

        //Connect();
    }

    public void Connect() {

        if (PhotonNetwork.IsConnected) PhotonNetwork.JoinRandomRoom();
        else {

            PhotonNetwork.ConnectUsingSettings();
            PhotonNetwork.GameVersion = gameVersion;
        }
    }

    public override void OnConnectedToMaster() {

        print("OnConnectedToMaster");

        PhotonNetwork.JoinRandomRoom();
    }

    public override void OnDisconnected(DisconnectCause cause) {

        print("Someone left because " + cause);
    }

    public override void OnJoinRandomFailed(short returnCode, string message) {

        print("OnJoinRandomRoomFailed");
        PhotonNetwork.CreateRoom(null, new RoomOptions { MaxPlayers = maxPlayersPerRoom } );
    }

    public override void OnJoinedRoom() {

        if (PhotonNetwork.CurrentRoom.PlayerCount == 1) PhotonNetwork.LoadLevel("Room1");
    }
}

I don't know what's wrong, and I've scrubbed the Internet to no avail to try and find a solution to this problem. So, help would be much appreciated.

Thanks in advance!

Comments

  • JohnTube
    JohnTube ✭✭✭✭✭
    Options
    Hi @LyghtningWither,

    Thank you for choosing Photon!

    The logs show that you tried to join a random room while the client is already in the process of joining a room.
    This is probably due to calling the same method more than once.
    Make sure JoinRandomRoom or CreateRoom are called once per attempt (success or failure).

    Maybe you're clicking Play too many times without waiting for feedback.

    Maybe replacing IsConnected with IsConnectedAndReady helps.
    Maybe adding "isConnecting" field as shown here helps.