Random Room Failing To Join

I have an issue where my code says to join a random room and if there isn't one, create your own. My issue is that I launch one client and it creates the room. I then launch another instance of the client and instead of joining the random room I just made, it instead creates it's own. The only work around I've found is to launch one client to make the room with a set name (such as "Room") and then edit the code on the other client to join "Room". But that's obviously not a real solution. Here's the code I got for this problem:
void OnJoinedLobby() {
Debug.Log ("OnJoinedLobby");
PhotonNetwork.JoinRandomRoom();
}

void OnPhotonRandomJoinFailed() {
Debug.Log ("OnPhotonRandomJoinFailed");
PhotonNetwork.CreateRoom( null );
}

void OnJoinedRoom() {
Debug.Log ("OnJoinedRoom");

SpawnMyPlayer();
}

Thanks

Comments

  • Maybe it's a timing problem. When you create a room you actually switch connection from one server to another and that adds a delay before you can join it randomly.
    This is especially a problem when you test and start both clients more or less at the same time.

    Please check if a short pause helps joining.
  • Waited about 5-10 minutes, tried multiple times and it's still joining separate rooms. You think it's a photon issue or something with my code?
  • Must be something in your code or project. I know that it's working for me usually.
    Please look out which player.ID you get in the room you join. In worst case, you ran into one bug we currently investigate: A player might get stuck forever and keep the room open. Then you would join that room and get a player.ID that will grow each time. If so, please mail me the appid, appVersion (GameVersion you send and PUN version) and the region you use.

    You could also try the "boxes" or "worker" demo in the PUN Free package. Those work for me.
  • Yea I definitely have some odd bugs going on. Basically if I join a room on one client, the game runs fine. When I connect with another instance of the client, they both join separate rooms and the controls/camera messes up (even though they're in different rooms). Like I can't turn my character or anything like that. Do you think this is my networking script that's messed up or my character movement script? I can PM you my network script but it's basically copy+pasted from a working source...
  • MrCoo1boy
    edited January 2014
    I had the same problem for players were joining different rooms, but I was able to fix it by changing
    void OnJoinedLobby() {
    Debug.Log ("OnJoinedLobby");
    PhotonNetwork.JoinRandomRoom();
    }
    To
    void OnJoinedLobby() {
    Debug.Log ("OnJoinedLobby");
    PhotonNetwork.JoinRandomRoom(null, 0); //0 means any amount of max players
    }

    And
    void OnPhotonRandomJoinFailed() {
    Debug.Log ("OnPhotonRandomJoinFailed");
    PhotonNetwork.CreateRoom( null );
    }
    To
    void OnPhotonRandomJoinFailed() {
    Debug.Log ("OnPhotonRandomJoinFailed");
    PhotonNetwork.CreateRoom(null, true, true, 100); //maxPlayer limit can be any amount
    }

    Let me know if that fix works for you.
  • > both join separate rooms and the controls/camera messes up (even though they're in different rooms)
    If it's ok while you are alone in a room, then why should it get broken when both join different ones? I guess both players do end up in the same room but your scripts collide and you get the impression you're not in the same room.
    Use the GUI to show a list of the users in the room or log out the "someone joined" callbacks.
  • When the Master Client creates the room, add a delay for 2-3 seconds before loading the multiplayer game scene. Now, when you open another scene window, client will automatically joins the room that master client created before.
  • I resolved this issue by checking the room properties which first player creates. There is a variable of Room named "IsOpen". If it is false then second player cannot join the same room. I just set it to true and now its perfectly joining the same room.
  • In my case its still not connecting to the same room.

    I have verified the gameVersion is correct, IsOpen is set to true, there is sufficient delay between the connection and loading the scene.

    For test purpose I made an exe output for windows. I ran 2 instances of the exe in the same system and was able to connect to the same room.

    When I run the exes in 2 different systems the users connect to separate rooms.

    The 2 exes running in the 2 different systems are exactly the same.
  • Kyriakos
    Kyriakos
    edited September 2020
    Hello! I have created a multiplayer game which tries to connect to a random room. If there is not one available, it creates one.
    On the same machine, first user creates the room and the next users successfully join without any problems.
    On a separate machine, first user creates the room but the next user on another machine takes too long and when is connected, the first user disconnects.
    PS1 I have preset default region.
    PS2 No errors are thrown in any of these cases
  • I have more or less the same problem as other people ... and it can't be the code as it has been working for months already and I did not change the code .

    The only thing I have changed is that I upgraded to PUN Plus, need I do something in the back end perhaps?
  • This is too vague to help and this thread is actually years old...
    Have a look at the Matchmaking Checklist and try to narrow things down. If you can't fix it, start a new thread with enough info to help us help you.