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
Documentation

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.

Read More on
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.

LeaveRoom and Disconnect are not working at all

modernator
2022-04-12 13:00:54

I'm calling PhotonNetwork.LeaveRoom() and PhotonNetwork.Disconnect() when the player decided to left the room after the match is over. However, seems like these two functions are just not working at all.

void HandleExit() {

if (PhotonNetwork.OfflineMode || PhotonNetwork.CurrentRoom == null) {

AsyncSceneLoader.LoadScene("Main");

}

else {

LanguageScheme locale = LanguageManager.Data;

AudioManager.PlayClickSound();

Dialog.Confirm(new ConfirmOptions() {

Message = locale.Multiplayer.Lobby.AskLeave,

OkText = locale.Multiplayer.Lobby.Leave,

CloseText = locale.Menu.Cancel,

OnClose = (confirmed) => {

if (confirmed == false) {

AudioManager.PlayCancelSound();

return;

}

AudioManager.PlayClickSound();

PhotonNetwork.LeaveRoom();

PhotonNetwork.Disconnect(); // DISCONNECT

print("Disconnect"); // It printed. So the above functions are surely invoked.

AsyncSceneLoader.LoadScene("Main");

}

});

}

}

But these two functions are doing nothing. Tested with a game object attached with a script that implemented IConnectionCallbacks and IMatchmakingCallbacks and OnLeftRoom and OnDisconnected callbacks are never invoked.

void OnEnable() {

PhotonNetwork.AddCallbackTarget(this);

}

public void OnLeftRoom() {

print("Left Room"); // NOT PRINTED

}

public void OnConnected() {

print("Connected");

}

public void OnConnectedToMaster() {

print("Connected to master");

}

public void OnDisconnected(DisconnectCause cause) {

print("Disconnected: " + cause.ToString()); // NOT PRINTED

}

Turned on Support Logger and set PUN Logging to "Informational", and couldn't see any information that OnLeftRoom and OnDisconnected callbacks invoked.

Since the game is still connected to the game server, I can't play offline mode with these error messages.

Can't start OFFLINE mode while connected!

CreateRoom failed. Client is on GameServer (must be Master Server for matchmaking)but not ready for operations (State: Disconnecting). Wait for callback: OnJoinedLobby or OnConnectedToMaster.

I'm even calling PhotonNetwork.Disconnect() again right before the start of offline game mode.

void StartGame() {

PlayConfirmSound();

PhotonNetwork.Disconnect();

PhotonNetwork.OfflineMode = true;

if (PhotonNetwork.InRoom == false) {

PhotonNetwork.CreateRoom(null);

}

AsyncSceneLoader.LoadScene("sv_island");

}

I have no idea what am I missing. Why those functions are not working?

Using Pun: 2.4.0 Photon lib: 4.1.6.11, Unity 2019.4.3f1.

Comments

Back to top