Networked Destroy + buffered RPC
Options
gnoblin
✭
Hello!
I instantiate an object via
I then destroy it via
It works OK, until I add sending buffered RPCs (doesn't matter from which view I send it).
using Destroy now - leads to
specifically:
I think it contains a hashtable instead of int (but I have nooo idea why) :shock: .
What am I doing wrong? :?
thanks,
Slav
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
0
Comments
-
Btw, I'm using version 1.1 of the package from the asset store.
Is this one the most up to date one?0 -
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).0 -
I experienced the same invalid cast error and fixed it the same way.0
-
Buffered rpc seems not to work because of trying to get int instead of Hashtable[(byte)0].0
-
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).0
-
When we call
PhotonNetwork.Destroy()
thennetworkingPeer.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); }
whereDoDestroyPhotonView(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 hereDestroyPhotonView(view);
is called again.
which again (!) sendsOpRaiseEvent(PhotonNetworkMessages.Destroy, evData, true, 0, EventCaching.DoNotCache, ReceiverGroup.Others);
0 -
and that is something I don't yet understand .0
-
Oh, sorry.
Now I think I understand it :oops:.0 -
And this understanding led me to adding
DoDestroyPhotonView(view);
just beforebreak
.
It seems object wasn't destroyed on remote machines.
Grenade is working now.0 -
Is the fix OK?0
-
After some thinking I must say I don't understand what is
if (orgPlayer != view.owner) { DestroyPhotonView(view); }
part for :? .0 -
There are indeed a few bugs in the 1.1 version, I've fixed these already and will submit an update to the assetstore.0
-
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.0 -
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.0 -
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.0 -
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?0
-
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.0