Error on rejoining the room in 1.62 ( for players instantiated with allocate view id )

Options
Neciq
Neciq
Hi,

We have problem with player that rejoins the same room.
[ Player A creates room, Player B joins it, then player B leaves it and joins again ]

The players in our game are created with buffered RPC instead of PhotonNetwork.Instantiate.
That is because we need to distinguish which prefab is needed to be instantiated ( local player has different prefab than remote player )
I suspect that this is connected to improper removing player ( at other players games ) as he leaves the game.
( He can leave e.g. by turning off his computer so he can not send any message to network to delete his peer )

The error appears at player's A game and is as follows:

MissingReferenceException: The object of type 'PhotonView' has been destroyed but you are still trying to access it.
Your script should either check if it is null or you should not destroy the object.
NetworkingPeer.RunViewUpdate () (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:3389)
PhotonHandler.Update () (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/PhotonHandler.cs:132)

This error did not occur on our previous version of the sdk ( from about 3 months ago )

One more thing - Another thing broke with latest sdk - When i try to unallocate viewid in OnPhotonPlayerDisconnected()
( PhotonNetwork.UnAllocateViewID(viewID); )
It does not work any more and generates an error ( No PhotonView )
This seems like to be connected with the main problem.

Please help !!

If PhotonNetwork.Instantiate is the only method supported right now for creating network objects - please tell me how I can distinguish which prefab to instantiate according to local or remote player.

Cheers,
Stan

Comments

  • Neciq
    Neciq
    edited October 2015
    Options
    Just quick thought - If our way to create network objects ( players ) is obsolete - we could use a callback that runs when PhotonNetwork.Instantiate() actually creates and object on other computers ( and self ) - This place would be good for re configuring player prefabs...
  • Neciq
    Options
    Update..

    I have confirmed this issue by making a simple experiment:
    - scene with 1 gameObject that has PhotonView component, and script "photon_test_main" ( sceneObject that synchronizes actions between all players)

    "photon_test_main" code:


    using UnityEngine;
    using System.Collections;

    public class photon_test_main : MonoBehaviour
    {
    PhotonView pv;
    public int option = 0;

    void Start ()
    {
    pv = GetComponent();
    PhotonNetwork.ConnectUsingSettings("v1.0");
    }

    void OnJoinedLobby()
    {
    if(option == 0)
    {
    RoomOptions ro = new RoomOptions();
    ro.isOpen = true;
    ro.isVisible = true;
    ro.maxPlayers = (byte)2;

    PhotonNetwork.CreateRoom("A", ro, null);
    }
    else
    {
    PhotonNetwork.JoinRoom("A");
    }
    }

    void OnJoinedRoom()
    {
    int id1 = PhotonNetwork.AllocateViewID();
    pv.RPC("OnPlayerJoined", PhotonTargets.AllBuffered, id1, PhotonNetwork.player.ID);
    }

    [PunRPC]
    void OnPlayerJoined(int viewID, int senderID)
    {
    GameObject newPlayer;
    if(senderID == PhotonNetwork.player.ID)
    {
    newPlayer = Instantiate(Resources.Load("Prefabs/Players/lp_test_photon")) as GameObject;
    newPlayer.GetComponent().viewID = viewID;
    newPlayer.name = "local";
    }
    else
    {
    newPlayer = Instantiate(Resources.Load("Prefabs/Players/lp_test_photon")) as GameObject;
    newPlayer.GetComponent().viewID = viewID;
    newPlayer.name = "remote";
    }
    newPlayer.transform.SetParent(transform, false);
    }

    public void OnPhotonPlayerDisconnected(PhotonPlayer player)
    {
    // this does not help ...
    for(int a=0; a();
    if(player.ID == pv.ownerId)
    DestroyRemote(p, pv);
    }
    }

    public IEnumerator DestroyRemote(GameObject p, PhotonView pv)
    {
    GameObject.Destroy(p);
    yield return 0;
    PhotonNetwork.UnAllocateViewID(pv.viewID);
    }

    void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
    {}
    }


    variable public "option" works for specifing room creator and joining player.

    Do You have any news on this issue ?
    Thanks,

    Stan
  • Tobias
    Options
    We could use a repro case.
    Can you share the project with us via mail?