Offline mode connecting online anyway!
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).
Offline mode connecting online anyway!
SSGG
2016-09-22 08:01:59
Hi,
I'm having some trouble with the 'offline mode'. The multiplayer side is working fine as I expected, but I also added an option to play 'offline', as a simple single player practice mode. For that, I thought all that was required was to add in the line; PhotonNetwork.OfflineMode = true, and then 'connect' as normal.
Anyway, the game runs as expected when choosing the offline mode, so I thought it was working fine...until someone joined my game! And at other times running 'offline' mode, I'd join other online games in progress.
It just seems that offlinemode is being reset to online mode immediately. i don't toggle the mode after the initial choice in the main menu, so I don't think I've left some rogue code in there setting offline mode to false. In fact I even stepped into the code, adding some debugging, and it's as if the game connects online of it's own accord.
After setting offlinemode to true, I added a 'connected?' check on the next line of code, which returns true (even though it's not got to the 'connect' command), i then call the disconnect() function and set offline mode to true again. This is even more confusing because the button to choose 'offline' is only shown in the OnGUI() function if 'connected is false'.
Here's the code stripped down.
void OnGUI()
{
if (!PhotonNetwork.connected)
{
if (GUI.Button(new Rect((Screen.width / 2) - 150, (Screen.height / 2) , 300, 40), "Play Offline"))
{
PhotonNetwork.offlineMode = true;
print("offline 1? " + PhotonNetwork.offlineMode.ToString());
if (PhotonNetwork.connected)
{
Debug.Log("connected, so disconnect");
PhotonNetwork.Disconnect();
PhotonNetwork.offlineMode = true;
print("offline 2? " + PhotonNetwork.offlineMode.ToString());
}
PhotonNetwork.ConnectUsingSettings("0.2");
PhotonNetwork.playerName = playerName;
print("offline 3? " + PhotonNetwork.offlineMode.ToString());
}
}
}
those 'debug/print' messages display the following when ran:
offline 1? true
connected, so disconnect
offline 2? true
offline 3? false
Does anyone have any ideas? I'm really confused...I wouldn't mind if it was just that I was doing something wrong after setting offline mode, but why does the PhotonNetwork.Connected return true at that time too?
Comments
Hi,
it's simply because you should not Connect to begin with when you are in offline mode. That doesn't make sense to connect to the server if you want to play offline.
simply have:
PhotonNetwork.offlineMode = true;
PhotonNetwork.CreateRoom("some name");
Your room will be created and you will be able to use PhotonNetwork.Instantiate() and RPC as usual.
Bye,
Jean
Ok thanks. Happy if it's me being an idiot, at least it's a quick fix then!
Why would it still think (PhotonNetwork.Connected) is true though? Does setting offline mode = true automatically create the 'fake' connection so that it then behaves as if connected (but just with itself)?
Hi,
It's indeed faking a connection, but simply doesn't send anything to a server.
Bye,
Jean
Back to top