- Home /
Network.instantiate & RPC destroy
Hello all,
Im learning slowly to work with networking. I'm now faced to the following problem:
I instantiate an 'enemy' projectile object using:
Rigidbody instantiatedProjectile = Network.Instantiate(projectile, spawnPoint.transform.position, spawnPoint.transform.rotation, 0) as Rigidbody;
No problem for now.
The problem is when I need to destroy this object; i've tried several solutions (including network.destroy) but the only one that seems to be working every time is:
networkView.RPC("killEPrjt001", RPCMode.All);
[RPC]
void killEPrjt001()
{
Network.RemoveRPCs(networkView.viewID);
Destroy (gameObject);
}
The object is correctly deleted on both server and client, the problem is that I receive the following errors when the object is beeing destroyed:
View ID AllocatedID: 20 not found during lookup. Strange behaviour may occur
Could't invoke RPC function 'killEPrjt001' because the networkView 'AllocatedID: 20' doesn't exist
Once again, visually everything is OK, I just wonder how to destroy the object without having such an error poping every time one of these projectile is destroyed (almost every second...)
Thank you for any help possible GrKl
Answer by GrKl · Jan 02, 2014 at 10:11 PM
Appologies, the code given above is correct, I was actually calling twice my RPC thus it was giving me this error... sorry
Answer by Hunt_Dialga · Dec 30, 2013 at 01:15 PM
I'm not exactly an expert at this, but from what I can see, it looks as if you are calling the function 'killEPrjt001' after the allocatedID for that RPC function has been destroyed. ( or something like along those lines )
From my experiences with errors of destroyed objects, you should be able to just make an 'if' statement saying if the allocatedID exists then to do the function. I would show you how you could do it, but I'm not exactly anywhere good at networking.
If you cant get it to work from there I'm all out of ideas. I believe you could just leave it alone if it visually looks OK. I can see how something like this could get annoying if it persists, but I don't think the consumers would know that there is an error in the RPC networking function. And I doubt they'll care as long as the game runs fine.
I hope my "expertise" help helped.
Answer by inkspot · Dec 30, 2013 at 01:52 PM
I think this error is produced because both ends are detroying the object, so if the server destroys it first the client is of course unable to find it. you could try this:
if(networkView.isMine)
or depending on your context
if(Network.isServer) or if(Network.isClient){
Thank you both (Hunt_Dialga & inkspot)
I have indeed looked on these paths, but could'nt find any working.
If I check if network view is$$anonymous$$e, I get the same errors. If I check if network is server or client, clients or server do not destroy the object If I only check this for: Network.RemoveRPCs(networkView.viewID); but leave the destroy outside the 'IF' statement, then always the first error
I feel like I'm turning is circle...
idk the context of the code, but is your ALL in RPC$$anonymous$$ode.All neccesary ? => RPC$$anonymous$$ODES
I had this error myself before, and the deter$$anonymous$$ing who destroys the object solved it for me with a projectile i assume that the 'shooter' knows already the info of the projectile and thus should only be send to others like RPC$$anonymous$$ode.Others I used this code for my network projectile, no [RPC] on top of the function:
function spawnexplosion() {
if(networkView.is$$anonymous$$ine)
{
Network.Instantiate(explosionparticle, transform.position, transform.rotation, 0);
Network.RemoveRPCs(networkView.viewID);
Network.Destroy(gameObject);
}}
Yes, the 'All' is neccesary, as I do not use network.destroy, just destroy so all (clients & server) need to have this instruction to destroy their GO
your code is ok, but the problem in using network.destroy is that it is not buffered. Thus if a client joins later in the game he will instantiate all your 'explosionparticle' that were instantiated before he logged in, but he will not destroy them as he did not receive the instruction to do it
Your answer
Follow this Question
Related Questions
Tell if remote Network.Instantiate object still exists 1 Answer
destroy player cloned weapon (multiplayer 1 Answer
Don't destroy player after disconnecting or calling ClientScene.RemovePlayer() 1 Answer
Help me please with Unity Multiplayer 1 Answer
Destroy player on spawn if he already exists in scene 1 Answer