Search Unity

Third Party [PUN] [Multiplayer] Scene synchronization problem after leaving room.

Discussion in 'Multiplayer' started by shohagmist, Jan 19, 2016.

  1. shohagmist

    shohagmist

    Joined:
    May 19, 2015
    Posts:
    37
    I am building a 2 player multiplayer system where One player creates a room and another player "joins randomly" to a room.
    this is my Awake function in the online menu scene.

    Code (CSharp):
    1. void Awake()
    2.     {
    3.                //I have to do this because if player leaves this scene and again enter this scene, he can't join or create any room.
    4.         if (PhotonNetwork.connected)
    5.         {
    6.             PhotonNetwork.Disconnect ();
    7.         }
    8.         PhotonNetwork.automaticallySyncScene = true;
    9.  
    10.         if (PhotonNetwork.connectionStateDetailed == PeerState.PeerCreated)
    11.         {
    12.             PhotonNetwork.ConnectUsingSettings ("0.9");
    13.         }
    14.  
    15.         if (string.IsNullOrEmpty (PhotonNetwork.playerName))
    16.         {
    17.             PhotonNetwork.playerName = Guest"+Random.Range(101, 10000);
    18.        }
    19.  
    20.    }
    21.  
    22. void FixedUpdate()
    23.    {
    24.        if (!PhotonNetwork.connected) {
    25.            if (PhotonNetwork.connecting) {
    26.  
    27.                connectionStatus.text = "Connecting to server...";
    28.              
    29.            }
    30.        }
    31. }
    32.  
    Now I firstly tried JoinRandomRoom(), if it fails i.e. inside OnPhotonRandomJoinFailed() function, a room will be created by the player and he will wait for player. Now, my problem is, if two players try to join a room and if they fails and one of them "Go Back" to "Main Menu", other one automatically goes to that scene. Even if the room joining is failed.

    I make PhotonNetwork.automaticallySyncScene = false, in the "Go Back" button's action method. But still it's not working properly.

    The most ridiculous scenario is: After coming back to "Main Menu" scene, I can't go to the "Online Menu Scene" again. I have to clear the App Data from mobile settings, then it works. One thing is, user have to login with Facebook/Google.

    Please help me someone. and ignore any syntax error in the code.
     
  2. shohagmist

    shohagmist

    Joined:
    May 19, 2015
    Posts:
    37
    Dear @tobiass , can I draw your attention in this case?
     
  3. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,066
    None of this shows or explains when and how you load scenes.
    If the player never makes it into the room, the automaticallySyncScene should not do anything.

    If you want to use automaticallySyncScene = true, then also use PhotonNetwork.LoadLevel(), so it can set the current scene's name in the room properties.
     
  4. shohagmist

    shohagmist

    Joined:
    May 19, 2015
    Posts:
    37
    After a banging my head for 2 days, i have solved this. This was not happening for PUN.