Problem with multiple players in rooms

I recently stumbled across a problem in my matchmaking code where the second person to join a two-player room cannot start the game. After debugging, I found that for the person who joined a room after it was created, is returning 1 at the time that the person who created the room is getting a value of 2 from the same call. Because my code checks to make sure there are two people in a room before starting the game on each side, this is preventing my multiplayer game from starting. This is a recent bug that's occurring even though I haven't changed my actual matchmaking scripts (although I recently just refactored so that I'm running PhotonNetwork in offline mode when playing a single player game, instead of only using PhotonNetwork for multiplayer like I did before). Does anyone know what might be causing this error?


  • Your refactoring might be causing this. Make sure that's not the case.
    Please update to the latest PUN version from the Asset Store and try again. If the problem stays, we can have a look (but I'm relatively sure this works).
  • I just updated PUN, but no luck.

    My refactoring was mostly on stuff that occurs after the matchmaking code. The only thing I changed prior to matchmaking was making sure PhotonNetwork.offline was set to true upon startup and then changed to false after the player selects multiplayer. I wonder if the refactoring somehow indirectly affected the matchmaking scripts, but if it did I have no idea how to find the root of the problem.

    It appears that player 2 is still connected to player 1 because when I exit a game as player 1, player 2 prints "Received event Leave for unknown actorNumber: 1". It's just that when it joins the room it won't start the game on its side due to there supposedly only being one player in the room.
  • After working on it all day, I was able to fix the issue, although I still can't say why what I did fixed it. Perhaps someone here will have an insight into that, or what I did will be useful to someone in the future.

    In my menu screen, I had PhotonNetwork.offlineMode set to true and only changed it to false when the player selected multiplayer. However, when I changed it so that offlineMode didn't get set to true until the player chose a single player game (still setting offlineMode to false when multiplayer was selected, just in case) it worked. Again, I'm not sure why this should have an affect and it might present a problem further down the road if the player changes their mind after selecting single player and goes back to the menu screen. But for now, it works.
  • Were/are you using the latest PUN version (1.14)? We have fixed some offlinemode issues in one of the last updates.
  • I think I now found the cause for this issue: Could it be that you set the player's names to null or ""?
    If you don't have any properties on a player, the current code does not create the list of players correctly. This leads to bad player counts which you reported.
    The fix you made by chance is that you are now using a name maybe.

    I will fix this for the next update.
Sign In or Register to comment.