Can't start OFFLINE mode while connected!
Options
So I'm currently trying to make player able to create a single-player room. My current code to set offline mode to true looks like this:
Thanks in advance!
public void SwitchConnection(bool connect) { if (connect) { PhotonNetwork.OfflineMode = false; } else { PhotonNetwork.OfflineMode = true; }However, when I set it to true, it gives me "Can't start OFFLINE mode while connected!" which makes no sense to me because I checked and this error gets thrown when IsConnected is true and it is true even in offline mode. So how can I possibly resolve this?
Thanks in advance!
0
Comments
-
Looking at my own code here, it seems that if you're connected you need to disconnect before starting an offline game.
async UniTask ConnectOfflineAsync() { // When in online mode and connected, first disconnect. if (!PhotonNetwork.OfflineMode && PhotonNetwork.IsConnected) await DisconnectAsync(); // Then change mode to offline. PhotonNetwork.OfflineMode = true; // And try connecting. await ConnectAsync(); }
1 -
Thanks, but I already figured this out on my own and did it the same way using Coroutines. So, for anyone reading this in the future, what do you need to know when implementing offline mode:
- Don't connect to master after going offline
- Create room without joining lobby as it will throw up an error otherwise
- Disconnecting doesn't happen immediately, so you might want to use something like this:
IEnumerator Disconnect() { PhotonNetwork.Disconnect(); while (PhotonNetwork.IsConnected) { yield return null; } PhotonNetwork.OfflineMode = true; }
0 -
Disconnect will attempt to reach the server and tell it the client disconnects. This makes sure the remaining players know asap.
There is a callback which tells you when the client is disconnected, so you don't have to make this a coroutine (but it's OK).1