I am getting this error:
Could’t invoke RPC function because
the networkView doesn’t exist
I understand the error - i send a RPC from server to client and the RPC argument contains NetvorkViewID value that is not assigned right? So the unity drops the RPC because it thinks i am going to do some invalid operation. But i don’t care, i want to send the ID in advance, i want to handle it by myself. It is enough that there is no way how to serialize networkViewID into a byte stream… is there any way how i can simply do what i want without redundant errors and exceptions and RPC drops? Or do i have to write my own NetworkView system? RakNet is cool, but these limitations are driving me crazy. Thanks for answer.
2 Answers
2
You misinterpreted the error. It doesn’t complaint about a parameter of your RPC function. RPCs are always sent between two networkviews with the same viewid. If you send a RPC call from a certain NetworkView and it arrives on a client that doesn’t have this NetworkView, it can’t execute the RPC because the counterpart of the NetworkView is missing on this client.
If you’re familiar with network-sockets, NetworkViews work similar. Two clients and each of them have a NetworkView. The NetworkViewID actually “connects” the two NetworkViews. If there’s no NetworkView with the same NetworkViewID, the client can’t process the RPC since there’s no receiver.
If you placed a NetworkView in a scene, it automatically gets a viewid, hardcoded in the scene. If two clients load the same scene those NetworkViews will automatically “connected” since they share the same ID. When you use Network.Instantiate it will automatically create a new ViewID for the object and distributes it to all peers.
You have some kind of synchronisation error. You might have destroyed an object on one client but not on the others. Or you created an object without Network.Instantiate and forgot to manually sync the ViewID.
If it was me, I’d make sure I need to talk to objects that may not have been created yet. But, if I did, one way around is to use something else, besides the NetworkID, for the object keys.
I’m not sure if Unity creates some unique key for each item. But, worst case, number your orcs are you spawn them; send that in something like RPC.giveOrders("guard",4);, where you are trying to give an order to orc #4. Then perform your “if orc#4 exists yet” logic the same as before.
How, exactly, do you intend to 'send the ID in advance'? There are ways to set up networkView ViewIDs at runtime, but in all of them the end result is that RPC calls just work properly. If you are getting this error, chances are you're doing something wrong.
– syclamothI am telling one NetworkView (that is already set up and working on both server and client ) about some other networkView (target, parent, whatever). So server is calling a RPC that contains another NetViewID as argument on client. Client should process this ID, find the object related to it and then do something with it. In case the object doesn't exist (yet) the clientside object can just wait for it. But it's not working because unity tries to protect me from bad ID
– Pangamini