Offline Mode

Offline mode is a feature to be able to re-use your multiplayer code in singleplayer game modes as well.

The most common features that you'll want to be able to use in single player are sending RPCs and using PhotonNetwork.Instantiate. The main goal of offline mode is to disable null references and other errors when using PhotonNetwork functionality while not connected. You would still need to keep track of the fact that you're running a single player game, to set up the game etc. However, while running the game, all code should be reusable.

You need to manually enable offline mode, as PhotonNetwork needs to be able to distinguish erroneous from intended behaviour. Enabling this feature is very easy:

once set to true, Photon will callback with the call OnConnectedToMaster() and then you can create a room, this room will be of course Offline too.

You can now reuse certain multiplayer methods without generating any connections and errors. Furthermore there is no noticeable overhead. Below follows a list of PhotonNetwork functions and variables and their results during offline mode:

  • PhotonNetwork.player: The player ID is always -1.
  • PhotonNetwork.playerName: Works as expected.
  • PhotonNetwork.playerList: Contains only the local player.
  • PhotonNetwork.otherPlayers Always empty.
  • PhotonNetwork.time: returns Time.time.
  • PhotonNetwork.isMasterClient: Always true.
  • PhotonNetwork.AllocateViewID(): Works as expected.
  • PhotonNetwork.Instantiate: Works as expected.
  • PhotonNetwork.Destroy: Works as expected.
  • PhotonNetwork.RemoveRPCs/RemoveRPCsInGroup/SetReceivingEnabled/SetSendingEnabled/SetLevelPrefix: While these make no sense in single player, they will not hurt either.
  • PhotonView.RPC: works as expected.

Note that using properties or methods other than the ones above can yield unexpected results and some will simply do nothing. e.g. will, obviously, return null. If you intend on starting a game in single player, but move it to multiplayer at a later stage, you might want to consider hosting a 1 player game instead; this will preserve buffered RPCs and instantiation calls, whereas offline mode instantiations will not automatically carry over after connecting.

Either set PhotonNetwork.offlineMode = false; or simply call Connect() to stop offline mode.

 To Document Top