The Photon Forum
is Closed Permanently.

After many dedicated years of service, we have made the decision to retire our Forum and switch to read-only: we´ve saved the best to last! Your search result can be found below. Plus, we offer support via these channels:

Try Our
Documentation

Please check if you can find an answer in our extensive documentation on PUN.

Join Us
on Discord

Meet and talk to our staff and the entire Photon-Community via Discord.

Read More on
Stack Overflow

Find more information on Stack Overflow (for Circle members only).

Write Us
an E-Mail

Feel free to send your question directly to our developers.

Why OnJoinedRoom() Not Woking?

Storm
2019-04-20 21:17:54

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().progressLabel.SetActive(true);  
        GameObject.Find("MenuManager").GetComponent().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.

Comments

Storm
2019-04-20 21:19:32

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()

Tobias
2019-04-24 14:57:27

Enable the SupportLogger component in the PhotonServerSettings and verify that OnJoinedRoom is not being called. If that logs OnJoinedRoom, your component is either being destroyed or otherwise unregistered from the callbacks-list in PUN.

Storm
2019-05-06 18:20:26

I found the problem, I was using a loading screen scene before the gamescene. I disabled the "autosyncscene" and problem solved. Thanks!

Urzathran
2022-07-11 21:12:58

I've come across a similar issue. My first couple callbacks work fine (OnConnectedToMaster(), OnJoinRandomFailed()), and the script keeps running with no errors after doing CreateRoom, but even with SupportLogger enabled, I get no callback for OnCreatedRoom, OnJoinedRoom, or even OnJoinRoomFailed.

BUT! I did realize I was trying to do this for HTML5; when I rebuilt for PC Standalone, it works as expected. Do I need to change a setting somewhere to have it queue up for browser connecting?

Back to top