Why OnJoinedRoom() Not Woking?

Hello,

In the game, player 1 tries to join a random room, if fails creates a room, this is working perfectly. Player 2 tries to connect to random room, it connects and game starts, this is also working. The problem is, Player 2 does not enter the OnJoinedRoom() callback, I don't know why... Can you please help me? I coded all callbacks and none of them give any warning...
public void Connect()
    {
        Debug.Log("LauncherLog: Connect Function started.");
        isConnecting = true;
        GameObject.Find("MenuManager").GetComponent<MenuManager>().progressLabel.SetActive(true);
        GameObject.Find("MenuManager").GetComponent<MenuManager>().controlPanel.SetActive(false);
        
        if (PhotonNetwork.IsConnected)
        {
            Debug.Log("LauncherLog: Is connected to photon and will try to join random room.");
            PhotonNetwork.JoinRandomRoom();
        }
        else
        {
            Debug.Log("LauncherLog: Not Connected to Photon, reconnecting...");
            PhotonNetwork.GameVersion = gameVersion;
            PhotonNetwork.ConnectUsingSettings();
        }
    }

public override void OnJoinRandomFailed(short returnCode, string message)
    {
        Debug.Log("LauncherLog: Player join random room failed with error " + message);
        PhotonNetwork.CreateRoom(null, new RoomOptions { MaxPlayers = maxPlayersPerRoom});
    }

public override void OnJoinedRoom()
    {
        Debug.Log("LauncherLog: OnjoinedRoom Function started.");
        StartCoroutine(MoveToGameScene(2));
    }

private IEnumerator MoveToGameScene(int SceneIndex)
    {
        Debug.Log("LauncherLog: MoveToGameScene started.");
        PhotonNetwork.IsMessageQueueRunning = false;

        if (PhotonNetwork.IsMasterClient)
        {
            Debug.Log("LauncherLog: MoveToGameScene is master client!, will close room");
            PhotonNetwork.CurrentRoom.IsOpen = false; // I make it true, in the loaded scene.
            Debug.Log("Room closed");
        }

        LoadingScreenPro.LoadScene(SceneIndex);
        yield return null;
    }
PLAYER 1 LOG (Works perfectly):
LauncherLog: Connect Function started.
LauncherLog: Is connected to photon and will try to join random room.
LauncherLog: Player join random room failed with error No match found
LauncherLog: Player created room.
LauncherLog: OnjoinedRoom Function started.
LauncherLog: MoveToGameScene started.
LauncherLog: Is master client!, will close room
LauncherLog: LS-Pro LoadScene started with Scene No 2
LauncherLog: GameScene Started.
LauncherLog: Room Opened

PLAYER 2 LOG (Works strange...):
LauncherLog: Connect Function started.
LauncherLog: Is connected to photon and will try to join random room.
LauncherLog: GameScene Started.

Best Answer

Answers

  • StormStorm
    edited April 20
    Btw, I use following callbacks and I dont get any warning... I use PUN2 v2.9

    OnConnectedToMaster()
    OnJoinedLobby()
    OnLeftLobby()
    OnPlayerEnteredRoom(Player newPlayer)
    OnLeftRoom()
    OnJoinRoomFailed(short returnCode, string message)
    OnCreateRoomFailed(short returnCode, string message)
    OnCreatedRoom()
    OnDisconnected(DisconnectCause cause)
    OnPlayerLeftRoom(Player otherPlayer)
    OnJoinRandomFailed(short returnCode, string message)
    OnJoinedRoom()
  • StormStorm
    I found the problem, I was using a loading screen scene before the gamescene. I disabled the "autosyncscene" and problem solved. Thanks!
Sign In or Register to comment.