OnCreatedRoom() and OnJoinedRoom() not being called

Hi,

I am new to PUN 2 and are making my way through trying to set up my first room. I have managed to setup my Unity project so it connects to the PUN 2 server. However when I try to CreateARoom, OnCreatedRoom() and OnJoinedRoom() do not get called. Am I doing something wrong?

Here is my code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Photon.Realtime;
using Photon.Pun;

public class CreateRoom : MonoBehaviourPunCallbacks
{
    // Start is called before the first frame update
    void Start()
    {

    }

    public void OnClick_CreateRoom()
    {
        if (!PhotonNetwork.IsConnected)
        {
          Debug.Log("NOT CONNECTED TO PHOTON NETWORK");
          return;

        }

        //Create the room
        RoomOptions options = new RoomOptions();
        options.MaxPlayers = 4;
        PhotonNetwork.CreateRoom("test", options, TypedLobby.Default);
        UIManager.Instance.startScreen.SetActive(false);
        UIManager.Instance.roomScreen.SetActive(true);


    }

    public override void OnCreatedRoom()
    {
        Debug.Log("Created room successfully", this); 
    }

    public override void OnJoinedRoom()
    {
        Debug.Log("Joined room successfully", this); 
    }

    public override void OnCreateRoomFailed(short returnCode, string message)
    {
        Debug.Log("Created room failed: " + message, this); 
    }


}

Any help would be greatly appreciated!

Thanks,

Dan

Comments

  • Figured it out. It was because I was setting startScreen to SetActive(False) it meant that the script that was running the CreateRoom was getting turned off before it could connect!
Sign In or Register to comment.