Cannot Join a room the second time around

Options
Hi there. I'm developing an application that requires, as I'd imagine most applications do, Joining/Creating a room -> Quitting out -> and then rejoining/creating another room.

This was working fine when the room join co-incided with a scene change, but due to technical constraints, the game now utilises an additive load when switching from menu to game. Unfortunately, the second time around going back into the room, I fail to join, and indeed even fail to get the OnPhotonRandomJoinFailed() callback.

Code below, this is the class that handles connections when the main game scene is loaded.
 
private const float ConnectionTimeOut = 8.0f; //How long a player can wait before we boot em out for not being able to connect
private float connectionTimer = 0.0f;

void Start () {
UserDetails.Instance.LoadGameProgress();
InvokeRepeating("AttemptConnection", 0.0f, 2.0f); //Attempt a connection every two seconds.
}
//Attempts to connect to room, invoked repeatedly until the connection/created room is connected too, or we timeout
void AttemptConnection()
{
if (PhotonNetwork.inRoom == false)
{
if (!PhotonNetwork.connected)
{
Debug.Log("Attempting Connecting to Photon");
// PhotonNetwork.ConnectUsingSettings("v1.0");
}
else if((PhotonNetwork.connectedAndReady) && (PhotonNetwork.inRoom == false))
{
Debug.Log("Attempting Joining Random Room");
PhotonNetwork.JoinRandomRoom();
}

}
}
void Update () {
connectionTimer += Time.deltaTime;
ReturnToMenuAfterTimeOut();
}
private void ReturnToMenuAfterTimeOut()
{
if ((PhotonNetwork.inRoom == false) && (connectionTimer > ConnectionTimeOut))
{
PhotonNetwork.LeaveRoom();
Application.LoadLevel("MenuScreen");
}
}
void OnJoinedRoom()
{
Debug.Log("JoinedRoom");
}
void OnCreatedRoom()
{
Debug.Log("CreatedRoom");
}
void OnPhotonRandomJoinFailed()
{
Debug.Log("Join Random Room Failed");
string roomToJoin = "Room" + PhotonNetwork.GetRoomList().Length.ToString();
Debug.Log("Attempting Joining/Creating Room : " + roomToJoin);
PhotonNetwork.JoinOrCreateRoom(roomToJoin, new RoomOptions() { maxPlayers = 20 }, TypedLobby.Default);
}
void OnPhotonCreateGameFailed()
{
Debug.Log("Failed to create room");
}
The debug output from this is as follows - We are already connected to photon from the main menu, there are no other players, and thus should be no rooms
FIRST JOIN.
Attempting Joining Random Room
Join Random Room Failed
Attempting Joining/Creating Room : Room0
JoinedRoom
GAMEPLAY
QUIT GAME
SECOND JOIN
Attempting Joining Random Room
Attempting Joining Random Room
Attempting Joining Random Room
Attempting Joining Random Room
CONNECTION TIMES OUT - BACK TO MENU.

The failure to connect/trigger failure callback occurs just the same when I attempt to create a room directly rather than relying on the callback.

When I quit the game, I call PhotonNetwork.LeaveRoom() from the player class. I suspected (and still do somewhat,) that something from my game scene was being carried back into my menu scene and then back over again into the game scene via the additive load, but as far as I can tell everything that should be getting destroyed is.

So, has anyone ever seen anything like this before/got any ideas what's going on? Any help appreciated, and apologies if I'm being inadvertently stupid. Thanks for taking a look.

Comments

  • kingsley
    Options
    I am having something similar going on on cloud server since about mid last week. Due to problem with "master staying connected" on Android, I am going into Lobby, then into game, doing various checks using "Disconnect" to go back to Lobby (to start from a clean slate again, Awake, etc) ... so far so good. then when reconnect have network time issues ... as if something is not being released with "Disconnect" command (or maybe I am expecting too much of it the wrong way).
  • kingsley
    Options
    I am using PhotonNetwork.JoinOrCreateRoom both times to connect but getting PhotonNetwork.time = 0 (which I test for) or my code is dodgy. :) 2 weeks ago it was fine, then intermittantly would connect, now never does.
  • static
    Options
    Put an output into my connection Update loop. PhotonNetwork.time ticks up as expected. Weirdly though, during the first successful connection, PhotonNetwork.time gets set to 0 for a period during the connection, and then begins to tick up from a new value again. However, on the second connection attempts, PhotonNetwork.time ticks up solidly without being set to 0 during the process.
  • static
    static
    edited November 2015
    Options
    It's the same story with ConnectionStateDetailed. On first connection I get the correct :
    JoinedLobby->ConnectingToGameServer->Authenticating-> Joining-> Joined statuses, but on my second connect attempt after quitting back to menu, It just sticks on joined lobby while calling PhotonNetwork.JoinRandomRoom()

    This is happening even if I completely disconnect/reconnect from Photon when quitting out of the game, going through the ConnectingToNameserver status process again. Really quite stumped.
  • static
    Options
    Updated from 1.57 to 1.63. No effect. Second connection is now displaying InMasterServer rather than JoinedLobby, but I believe this just to be the autoJoinLobby being disabled by default.
  • static
    Options
    So for anyone coming across this in the future, looks like I solved it, or at least found a workaround.

    My Additive-Async load from menu to gamescene was done on a sort of "Discard everything from menu, except what we want to keep" approach. I changed this to a "Keep everything from menu, except what we want to discard." For some reason, this fixed the issue. Don't know if Photon is spawning hidden objects or just something from my menu scene is required to be in the game-scene to connect the second time around, not a clue, there were no errors. In any case, it's fixed, for the moment.
  • Khudere
    Options
    This is exactly what i'm trying to figure out right now, it sticks me in lobby on the second time reconnecting. Trying to keep everything but that doesn't seem to be working either