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.

PhotonNetwork.LeaveRoom and disconnect all clients

2019-05-09 16:43:48

Dear professionals!
is it possible to call PhotonNetwork.LeaveRoom() on the master client and let the other clients also leave the room to close the room? Instead of using PhotonNetwork.Disconnect().
If we use PhotonNetwork.Disconnect(), sometimes, I can't connect to the master server, but I noticed that if I call PhotonNetwork.LeaveRoom(), I was able to connect to the Master server again and the error won't happen.
But when I call PhotonNetwork.LeaveRoom() on the master client, the master client changes and the other client becomes a new master client. But I don't want to change the master client and if the master client left the room, the other clients also need to left the room.
Please kindly let me know the best solution


2019-05-16 08:09:08

use RPC,call it from the master, them all players will leave

2019-05-16 08:15:04

Well. then if a player goes to the background, he will not receive the RPC command.

2019-05-16 11:19:25

Hi @sweetmei25,

What you could do is, from MasterClient:

  • Set CurrentRoom.IsOpen = false, CurrentRoom.IsVisible = false CurrentRoom.PlayerTtl= 0 and CurrentRoom.EmptyRoomTtl = 0.
  • Send a "disconnect even" to all CACHED (or buffered RPC), raiseEventOptions.CachingOption = CachingOption.AddToRoomCache or raiseEventOptions.CachingOption = CachingOption.AddToRoomCacheGlobal, this way when the actor who is in the background or inactive will leave as soon as joined to the room if that happens.
  • Leave the room.

Otherwise, your only options are server side via custom plugin or custom app. code.

Back to top