Photon doesn't disconnect from server

Hi,
I use Photon (PUN2) in my game. I game all system and its works (when you play the first game). The user connects to a server, lobby etc. Game, after the game user, should disconnect from the server and when wants play again just connect again to the server. Problem because the user can’t disconnect. Why?
First code, when Player finish the game.

public void EndMatch()
    {
        PhotonNetwork.LeaveRoom();
        PhotonNetwork.LeaveLobby();
        PhotonNetwork.Disconnect();
    }

The second one, when the user wants to leave the lobby:

public void OnClickLeaveLobby()
    {
        PhotonNetwork.LeaveRoom();
        PhotonNetwork.LeaveLobby();
        PhotonNetwork.Disconnect();
        Debug.Log("User left from Lobby");
        EnergySystem();
        loadSceneScript.LoadMainMenu();
    }

After both situation I got the same error “ConnectUsingSettings() failed. Can only connect while in state ‘Disconnected’. Current state: Connected”

Don’t do everything in one method.
Actually, you can simplify matters: Just disconnect. The server will know you have to leave the room or lobby, etc.

I use this function when the user is in the Lobby and join or create the room. The user has possible to leave the room.
When he/she presses the button
“User left from Lobby”
“Disconnect from the server”
" ConnectUsingSettings() failed. Can only connect while in state ‘Disconnected’. Current state: Connected".

public void OnClickLeaveLobby()
    {
        PhotonNetwork.Disconnect();
        Debug.Log("User left from Lobby");
        EnergySystem();
        loadSceneScript.LoadMainMenu();
    }
 public override void OnDisconnected(DisconnectCause cause)
    {
        base.OnDisconnected(cause);
        Debug.Log("Disconnect from the server");
    }

Which version of PUN is that?

It’s my error:

ConnectUsingSettings() failed. Can only connect while in state ‘Disconnected’. Current state: Connected
#0 GetStacktrace(int)
#1 DebugStringToFile(DebugStringToFileData const&)
#2 DebugLogHandler_CUSTOM_Internal_Log(LogType, LogOption, ScriptingBackendNativeStringPtrOpaque*, ScriptingBackendNativeObjectPtrOpaque*)
#3 (Mono JIT Code) (wrapper managed-to-native) UnityEngine.DebugLogHandler:Internal_Log (UnityEngine.LogType,UnityEngine.LogOption,string,UnityEngine.Object)
#4 mono_jit_runtime_invoke
#5 do_runtime_invoke
#6 mono_runtime_invoke
#7 scripting_method_invoke(ScriptingMethodPtr, ScriptingObjectPtr, ScriptingArguments&, ScriptingExceptionPtr*, bool)
#8 ScriptingInvocation::Invoke(ScriptingExceptionPtr*, bool)
#9 MonoBehaviour::CallMethodIfAvailable(int)
#10 MonoBehaviour::CallUpdateMethod(int)
#11 void BaseBehaviourManager::CommonUpdate()
#12 BehaviourManager::Update()
#13 InitPlayerLoopCallbacks()::UpdateScriptRunBehaviourUpdateRegistrator::Forward()
#14 ExecutePlayerLoop(NativePlayerLoopSystem*)
#15 ExecutePlayerLoop(NativePlayerLoopSystem*)
#16 PlayerLoop()
#17 PlayerLoopController::UpdateScene(bool)
#18 PlayerLoopController::UpdateSceneIfNeeded()
#19 Application::TickTimer()
#20 -[EditorApplication TickTimer]
#21 __NSFireTimer
#22 CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION
#23 __CFRunLoopDoTimer
#24 __CFRunLoopDoTimers
#25 __CFRunLoopRun
#26 CFRunLoopRunSpecific
#27 RunCurrentEventLoopInMode
#28 ReceiveNextEventCommon
#29 _BlockUntilNextEventMatchingListInModeWithFilter
#30 _DPSNextEvent
#31 -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:]
#32 -[EditorApplication checkForFocusChange:]
#33 __NSFireTimer
#34 CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION
#35 __CFRunLoopDoTimer
#36 __CFRunLoopDoTimers
#37 __CFRunLoopRun
#38 CFRunLoopRunSpecific
#39 RunCurrentEventLoopInMode
#40 ReceiveNextEventCommon
#41 _BlockUntilNextEventMatchingListInModeWithFilter
#42 _DPSNextEvent
#43 -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:]
#44 -[NSApplication run]
#45 NSApplicationMain
#46 EditorMain(int, char const**)
#47 main
#48 start
#49 ???

I don’t know what it’s wrong because the user connecting with the server.

I did a small break after disconnect (5 seconds) and before the change of the scene, but it doesn’t help. When I would like to start the next game I can’t connect with the server and go to the lobby.

Are you using PUN 2.33.3? If not, update and report if the problem is solved or not.
If not, we’d need some repro steps, I guess.

It’s okay. I solved it.

1 Like

Hi! Running the same issue here, could you share your solution?

I’m sorry but It was such a time ago I don’t remember what I did.