Networked Destroy + buffered RPC

Options
Hello!

I instantiate an object via
PhotonNetwork.Instantiate(grenadePrefab, transform.position, Quaternion.identity, 0);

I then destroy it via
PhotonNetwork.Destroy();

It works OK, until I add sending buffered RPCs (doesn't matter from which view I send it).

using Destroy now - leads to
InvalidCastException: Cannot cast from source type to destination type.
NetworkingPeer.RemoveRPCs (.PhotonView view) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:1666)
NetworkingPeer.DoDestroyPhotonView (.PhotonView view) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:1570)
NetworkingPeer.DestroyPhotonView (.PhotonView view) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:1564)
PhotonNetwork.Destroy (.PhotonView view) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/PhotonNetwork.cs:667)
PhotonNetwork.Destroy (UnityEngine.GameObject go) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/PhotonNetwork.cs:689)
GameManager.Test () (at Assets/Photon Unity Networking/DemoWorker/Scripts/Game/GameManager.cs:33)

specifically:
Hashtable removeFromCache = new Hashtable();
        foreach (DictionaryEntry entry in cachedRPCs)
        {
 Hashtable rpcData = (Hashtable)entry.Value;
            if ((int)rpcData[(byte)0] == view.viewID.ID)////here
            {
                removeFromCache[(int)entry.Key] = null;
            }
        }

I think it contains a hashtable instead of int (but I have nooo idea why) :shock: .

What am I doing wrong? :?

thanks,
Slav

Comments

  • gnoblin
    Options
    Btw, I'm using version 1.1 of the package from the asset store.
    Is this one the most up to date one?
  • gnoblin
    Options
    Another thing I've noticed that networked destroy didn't work well (without buffered rpc) while testing 2 players - because Destroy event came with PhotonViewID and upon receive the code was trying to cast it to int (and failed).

    I've fixed that and it _seems_ to work ok (now trying to fix a problem in post N1).
  • Boris
    Options
    I experienced the same invalid cast error and fixed it the same way.
  • gnoblin
    Options
    Buffered rpc seems not to work because of trying to get int instead of Hashtable[(byte)0].
  • gnoblin
    Options
    Right now I have no errors, but grenade instantiated from player2 doesn't want to be destroyed from player2 in player1's build (but that must be related to some my mistake... investigating).
  • gnoblin
    Options
    When we call
    PhotonNetwork.Destroy()
    
    then
    networkingPeer.DestroyPhotonView(view);
    
    is being called:
    public void DestroyPhotonView(PhotonView view)
        {
            Hashtable evData = new Hashtable();
            evData[(byte)0] = view.viewID;
            Debug.Log("sending destroy event");
            OpRaiseEvent(PhotonNetworkMessages.Destroy, evData, true, 0, EventCaching.DoNotCache, ReceiverGroup.Others);
    
            DoDestroyPhotonView(view);
        }
    

    where
    DoDestroyPhotonView(view);
    
    destroys the GameObject locally.

    Everything is logical...

    Another player get destroy event:
    case PhotonNetworkMessages.Destroy:
                    Debug.Log("destroy event");
                    Hashtable data = (Hashtable)photonEvent[ParameterCode.Data];
                    PhotonViewID viewID = (PhotonViewID)data[(byte)0];
                    PhotonView view = GetPhotonView(viewID.ID);
    
                    if (view == null || orgPlayer == null)
                    {
                        Debug.LogError("ERROR: Illegal destroy request on view ID=" + view.viewID + " from player " + orgPlayer.ID);
                    }
                    else
                    {
                        if (orgPlayer != view.owner)
                        {
                            DestroyPhotonView(view);
                        }
                    }
                    break;
    

    and here
    DestroyPhotonView(view);
    
    is called again.

    which again (!) sends
    OpRaiseEvent(PhotonNetworkMessages.Destroy, evData, true, 0, EventCaching.DoNotCache, ReceiverGroup.Others);
    
  • gnoblin
    Options
    and that is something I don't yet understand :).
  • gnoblin
    Options
    Oh, sorry.

    Now I think I understand it :oops:.
  • gnoblin
    Options
    And this understanding led me to adding
    DoDestroyPhotonView(view);
    
    just before
    break
    
    .

    It seems object wasn't destroyed on remote machines.

    Grenade is working now.
  • gnoblin
    Options
    Is the fix OK?
  • gnoblin
    Options
    After some thinking I must say I don't understand what is
    if (orgPlayer != view.owner)
                        {
                            DestroyPhotonView(view);
                        }
    
    part for :? .
  • Leepo
    Options
    There are indeed a few bugs in the 1.1 version, I've fixed these already and will submit an update to the assetstore.
  • gnoblin
    Options
    gnoblin wrote:
    After some thinking I must say I don't understand what is
    if (orgPlayer != view.owner)
                        {
                            DestroyPhotonView(view);
                        }
    
    part for :? .

    I commented it out, because it produced errors when
    playerB tried to destroy object belonging to playerA.

    I think I'll need to think everything over once 1.2 is out.
  • gnoblin wrote:
    Another thing I've noticed that networked destroy didn't work well (without buffered rpc) while testing 2 players - because Destroy event came with PhotonViewID and upon receive the code was trying to cast it to int (and failed).

    I've fixed that and it _seems_ to work ok (now trying to fix a problem in post N1).


    How did you fix it? I don't see you saying what you did?

    I'm doing

    GameObject newplayer = PhotonNetwork.Instantiate( PlayerCraft, _spawn.transform.position, _spawn.transform.rotation, 0) ;
    PhotonView _pv = (PhotonView)newplayer.GetComponent("PhotonView");
    _pv.RPC("mycommand", PhotonTargets.AllBuffered, (int)LocationID);


    I'm getting the same error and don't know how to fix? This worked perfectly under the legacy Unity3D networking. I just ported the code last night using the converter and finally tweaked it to get it to run. Now it's failing

    Any Help greatly appreciated.
  • Tobias
    Options
    Quadgnim:
    As I'm working towards a new release and heavily refactored the Instantiate/Destroy part: Can you please let me know if this problem still exists in the PUN 1.18 preview?

    If so, I'll have another look and fix it before release.
    Thanks.
  • I'm using the latest version from the web site so I would say yes. However I'm also using unity 4, not sure if that is an issue?
  • Tobias
    Options
    For me, calling an RPC on an instantiated GO works immediately (including the RPC method's call remotely).

    So I updated the preview package on dropbox (right now). The string versionPUN is "1.18p3" in it.
    The link is the old one from this post: viewtopic.php?f=17&t=2333 (I don't want to duplicate it in case it changes).

    When you can still produce the issue, please open a new thread and include the error's callstack.
    I can't match the old error stack with the current version.