1

Right I found this question asked elsewhere but I am really stuck at the point where none of the solution is unfortunately working.

So when the game gets over, I have to load either the menu screen or random battle screen or the friends screen. But somehow I am trying my heart out to disconnect when I click the random screen button and friends screen button. But it is just not disconnecting.

The code is as follows:

public class GameOverManagerMP : MonoBehaviourPunCallbacks
{
 
     public void OnClickRandomScreenButton()
        {
           MultiPlayerScoreManager.instance.NextSceneToBeLoaded = 
          "MatchMakingScreen";
           PhotonNetwork.LeaveRoom();
        }
    
        public void OnClickFriendsScreenButton()
        { 
         MultiPlayerScoreManager.instance.NextSceneToBeLoaded = "FriendsScreen";
         PhotonNetwork.LeaveRoom();
        }
    
         public override void OnLeftRoom()
         {
            Debug.Log("On left room executed in Game Over Manger class.........");
            base.OnLeftRoom();
            PhotonNetwork.Disconnect();
         }
    
        public override void OnDisconnected(DisconnectCause cause)
        {
            Debug.Log("On OnDisconnected executed in Game Over Manger class.........");
            base.OnDisconnected(cause);
            SceneManager.LoadScene( MultiPlayerScoreManager.instance.NextSceneToBeLoaded );
        } 
} 

So basically I got the error the screenshot is attached here:

operation leaveRoom(254) not called because Client is not............ 

So what I did was I put

if(PhotonNetwork.InRoom)
  PhotonNetwork.leaveRoom()

The error disappears but nothing happens, meaning the OnDisconnected Callback never executes...

I even tried this code

 if (PhotonNetwork.IsConnected)
        {
         StartCoroutine(Disconnect());
        }


IEnumerator Disconnect()
{
    PhotonNetwork.Disconnect();
    while (PhotonNetwork.IsConnected)
    {
        yield return null;
        Debug.Log("Disconnecting. . .");
    }
    Debug.Log("DISCONNECTED!");
}

But it doesn't hit the line "DISCONNECTED!". It is in an infinte loop with saying "Disconnecting..."

The whole part is when I stop playing in Unity, then the OnLeftRoom and OnDisconnected function gets executed . I have highlighed with a red rectangle around it in the screenshot as indicated above.

As per this answer, it is said that the callback OnConnectedToMaster will be executed. I implemented that callback also but nothing inside it is getting printed.Infact I implemented every callback, not is happening

In my game I have to disconnect entirely before connecting again but somehow it is not happening.How do you actually do it?

derHugo
  • 83,094
  • 9
  • 75
  • 115
chethanv77777
  • 480
  • 9
  • 18

1 Answers1

0

In the screenshot, you already see your log "On OnDisconnected". It may not load something but the client is disconnected and you got the callback.

Why you get the error logs: You seem to be calling PhotonNetwork.LeaveRoom() more than once while it processes. This is likely because there is no visible feedback to the user that the client will leave the room and reconnect to the Master Server. It does not Disconnect in this case. Call PhotonNetwork.Disconnect(), if you want the client to go offline and wait for the callback.

Tobias
  • 164
  • 2
  • Actually speaking what u said about error logs is right, that is why as I have mentioned in the question I put the condition if(PhotonNetwork.InRoom) then PhotonNetwork.LeaveRoom(). When I hit the stop play button in Unity only then OnDisconnected function executes. The question how do you leave the room or get disconnected after a battle is done? – chethanv77777 Feb 09 '22 at 10:33