Are your RPC's failing in offline mode?

Options
Make sure you don't set PhotonNetwork.OfflineMode = true; in Awake()... it doesn't work! Under Start() it works fine.

Comments

  • Hi @Alex_P,

    what makes you think, that it is not working in Awake? It basically doesn't matter where you enable it. The important aspect is, that you do it before creating a room.
  • Alex_P
    Options
    Hey @Christian_Simon,

    Just did some debugging and I can see the difference is when I have it in Awake(), OnConnectedToMaster() is never called and so a room is not created. When I put it in Start() OnConnectedToMaster() gets called as expected.

    Alex.
  • Make sure, that you don't connect to Photon by accident: you don't get the OnConnectedToMaster callback when you have enabled the Offline Mode. Also when using PhotonNetwork.ConnectUsingSettings();, this might overwrite the settings you have made before. To use this function, you have to check the 'Start In Offline Mode' option in the PhotonServerSettings.

    After enabling the Offline Mode in code, you can simply create a new room.
  • Alex_P
    Options
    @Christian_Simon

    Make sure, that you don't connect to Photon by accident: you don't get the OnConnectedToMaster callback when you have enabled the Offline Mode.

    I didn't realise about the Start in offline mode under settings, thanks!
    I'll just use that instead. It is true though, that if I call PhotonNetwork.OfflineMode = true; (no matter which setting I use under PhotonServerSettings), OnConnectedToMaster gets called. I just tested it with the bare minimum and my debug gets called...
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using Photon.Pun;
    using ExitGames.Client.Photon;
    
    public class NetworkManager : MonoBehaviourPunCallbacks
    {
    	// Use this for initialization
    	void Start ()
    	{
    		PhotonNetwork.OfflineMode = true;
    	}
    	
    	public override void OnConnectedToMaster()
    	{
    		Debug.Log("Connected to master");
    	}
    }
    And on further checking I see why under PhotonNetwork.cs line 420 ( :smile: )
    if (offlineMode)
    {
        NetworkingClient.ChangeLocalID(-1);
        //SendMonoMessage(PhotonNetworkingMessage.OnConnectedToMaster);
        NetworkingClient.ConnectionCallbackTargets.OnConnectedToMaster();
    }
  • Just noticed: whether OnConnectedToMaster gets called, depends on when you enable the Offline Mode. If you do this in Start, you will get this callback. If you do this in Awake, you won't get the callback because you probably haven't added the callback target (yet). By default AddCallbackTarget is used in OnEnable, which is called after Awake but before Start.