OfflineMode and weird viewID

Options
I am trying to run Photon in offlineMode and using PhotonNetwork.Instantiate to spawn my character, but for some reason, the PhotonView attached to my prefab, gets a negative viewID of -999, which later leads to errors in the RPC calls.

Any idea why that is?

As far as I see, the AllocateViewID(int ownerId) function in PhotonNetwork is calculating this ID to be negative.

Comments

  • vadim
    Options
    When do you switch to offline mode? What is client state when you trying to create object?
    Any warning or errors in log?
    Your player id is -1 that is not good.
  • kamend
    Options
    I do not switch to offline mode from a connected state, I directly create a room. Also Photon's code sets the Player ID as -1, if you are in offline mode.
  • kamend
    Options
    This is a proper bug btw..
  • Tobias
    Options
    When you set PhotonNetwork.offlineMode, we also set the local player's ID from -1 to 1.
    In your case, the PhotonNetwork.player.ID seems to be still -1, causing the issues.
    You have to set offlineMode explicitly! It is not enough to just not being connected. It's a different mode, which fakes being online.

    Do you join a room in offline mode? You should.
    Which version of PUN do you use?
  • kamend
    Options
    Hey Tobias,
    I am using the latest 1.58 from the Asset Store.

    Here are the steps I do:

    1) PhotonNetworking.offlineMode = true
    2) CreateRoom
    3) Instantiate

    I will test again and report where the problem is coming from.
  • Tobias
    Options
    I can't reproduce it with the simple steps.
    I instantiate in
    
        public override void OnCreatedRoom()
        {
            PhotonNetwork.Instantiate(prefabName, Vector3.zero, Quaternion.identity, 0);
        }
  • kamend
    kamend
    edited July 2015
    Options
    Well the Player.ID is 1 at the end of the process, but the problem is that when the PhotonView is calculating it's viewID, the player.ID is still -1, so the viewID is set to -999, I think you have the wrong order there.

    Here is the order of events and why it is wrong:

    1) I call PhotonNetwork.offlineMode = true

    2) which will come here (PhotonNetwork.cs)

    NetworkingPeer.SendMonoMessage(PhotonNetworkingMessage.OnConnectedToMaster); networkingPeer.ChangeLocalID(1);


    3)OnConnectedToMaster will call my callback whcih will create a room

    4) Then on Join, will Instantiate my player prefab with the photonView, but at this time, the change of LocalID is yet to be called

    5) After my player prefab is instantiated, the ChangeLocalID will be called


    My solution was to call:
    PhotonNetwork.networkingPeer.ChangeLocalID( 1 );

    inside my OnConnectedToMaster handler manually.
  • Tobias
    Options
    Ah, now I can reproduce it. The missing piece was: You create the room in OnConnectedToMaster.
    If you set the offline mode, OnConnectedToMaster is called before the actorNumber is set to 1.
    If you call CreateRoom, the callback OnCreatedRoom will be called immediately and all of that happens before the player number is 1.

    I was cheating a bit with the offline mode, because I set the player number on the (fake) Master Server (where you usually don't have one). It's not done (properly) when you join/create rooms.

    I will check out the code and fix the sequence.
    Thanks for the input and head up. Glad you could solve it, too.