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...
  • 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.
Sign In or Register to comment.