The Photon Forum
is Closed Permanently.

After many dedicated years of service, we have made the decision to retire our Forum and switch to read-only: we´ve saved the best to last! Your search result can be found below. Plus, we offer support via these channels:

Try Our

Please check if you can find an answer in our extensive documentation on PUN.

Join Us
on Discord

Meet and talk to our staff and the entire Photon-Community via Discord.

Stack Overflow

Find more information on Stack Overflow (for Circle members only).

Write Us
an E-Mail

Feel free to send your question directly to our developers.

How to disconnect from the server and connect for the second game?

2021-06-29 17:19:55

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.
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".


2021-06-30 09:54:05

You only need to call PhotonNetwork.Disconnect and wait for the disconnected callback.

If you didn't update PUN 2 in a while, please do. This might help avoid issues we fixed before.
Related Unity forum thread.

2021-06-30 18:06:29

Yes, but when I want to come back to the server and play again I can't.

2021-07-01 08:45:44

Have a look at the callstack for the error "ConnectUsingSettings() failed". This is called "too early". When you do a regular disconnect from the server, the client will tell the server it is diconnecting and this takes some communication. Wait for the callback OnDisconnected, before you call ConnectAndJoinRandom anywhere.

2021-07-18 23:37:34

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.

2021-08-30 15:13:32

Which version of PUN do you use? If it's not recent, please update.
Can you reproduce this with some of our demos? Without more concrete info, I have a hard time answering something useful...

Back to top