Can't start OFFLINE mode while connected!
The whole answer can be found below.
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).
Can't start OFFLINE mode while connected!
D3RRIXX
2021-02-25 13:08:00
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:
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!
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();
}
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; }
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).
Back to top