Why OnJoinedRoom() Not Woking?
The whole answer can be found below.
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).
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 2 LOG (Works strange...):
LauncherLog: Connect Function started.
LauncherLog: Is connected to photon and will try to join random room.
LauncherLog: GameScene Started.
Comments
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()
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.
I found the problem, I was using a loading screen scene before the gamescene. I disabled the "autosyncscene" and problem solved. Thanks!
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