pun 1.80 - after calling Disconnect() the networkingPeer.State stays in Disconnecting indefinitley

Options
My game is a multiplayer game, but have also a single player mode. After I upgraded to pun 1.80 I started to experience the following problem:

When a single player game is started this code is executed:
PhotonNetwork.Disconnect();
PhotonNetwork.offlineMode = true;
After the single player game finished (couple of minutes) and the player goes back to the main menu the PhotonNetwork.networkingPeer.State is still ClientState.Disconnecting, so I can't connect again!

trying to connect with this code:
PhotonNetwork.offlineMode = false;
PhotonNetwork.ConnectToRegion(CloudRegionCode.eu, "2.0");
does nothing and later I get errors when I try to join the lobby. Also PhotonNetwork.insideLobby is true!

If I use this code:
PhotonNetwork.Reconnect();
Then I get this error: Connect() failed. Can't connect while disconnecting (still). Current state: Disconnecting

Also it doesn't matter how long I wait, the status never changes from disconnecting to disconnected.
I am using now this workaround:
if(PhotonNetwork.networkingPeer.State == ClientState.Disconnecting)
	PhotonNetwork.networkingPeer.StopThread();

PhotonNetwork.ConnectToRegion(CloudRegionCode.eu, "2.0");
Is there a better way to handle this?

Comments

  • jeanfabre
    Options
    Hi,

    I think because you need to disconnect in both case:

    I tested this and it works fine, can you confirm it works on your end too?
    
    public class OfflineCreateAndInstantiate : PunBehaviour
    {
    
        public string prefabName;
    
        public void Start()
        {
            PhotonNetwork.offlineMode = true;
        }
    
        public override void OnConnectedToMaster()
        {
            PhotonNetwork.CreateRoom("");
        }
    
        public override void OnCreatedRoom()
        {
            PhotonNetwork.Instantiate(prefabName, Vector3.zero, Quaternion.identity, 0);
        }
    
        public void Update()
        {
    
        }
    
    
    	void OnGUI()
    	{
    		GUILayout.Label("State:"+PhotonNetwork.networkingPeer.State.ToString() );
    
    		if (PhotonNetwork.offlineMode )
    		{
    			if (GUILayout.Button("go Online"))
    			{
    				PhotonNetwork.Disconnect();
    				PhotonNetwork.offlineMode = false;
    				PhotonNetwork.ConnectUsingSettings("1.0");
    			}
    		}else{
    			if (GUILayout.Button("go Offline"))
    			{
    				PhotonNetwork.Disconnect();
    				PhotonNetwork.offlineMode = true;
    			}
    		}
    	}
    
    }
    
    Bye,

    Jean
  • kampfhund
    Options
    @jeanfabre Hi,

    I tested it and it works. Thanks!

    Bye

    Matey