- Home /
Need Help with function parameters and RPC parameters!
Hi, I asked a question Here, but afterwards i ran into a problem; I don't know what parameters to use in my RPC function, or how to format them. Here are some code snippets:
networkView.RPC("moveObject", RPCMode.Server, /*What do I put here?*/);
And:
@RPC
function moveObject(_rigidbody:Rigidbody,_vector:Vector3){
var finalVector:Vector3=(_vector-_rigidbody.transform.position);
_rigidbody.transform.Translate(finalVector*Time.deltaTime*10,Space.World);
}
Help is much appreciated!
Answer by fherbst · Aug 31, 2013 at 12:06 PM
See here for supported RPC parameters. You can't send a rigidbody refence. The standard way would be to have the networkView directly on a rigidbody (which is ceated by Network.Instantiate from the server) and to use the RPC call only with the position parameter.
By the way, syncing transform/rigidbody parameters is supported by default, so if your use case really is just moving stuff, just drag the Rigidbody component onto the NetworkView.
Thankyou for answering!
I think your answer is probably correct, but I'm having trouble understanding it and implementing these features into my script as I'm new to RPC calls.
Are you saying that I should perform the moveObject function Locally to the client, and then send an RPC call of the new position of the object?
I'm Completetly stumped as to what to do, I don't understand how to achieve this :(
Seems like you just need to remove the "rigidbody" variable and access it via this.rigidbody ins$$anonymous$$d. RPCs get called directly in the connected object.
I can't figure out how to do this so I'm going to try another approach that changes the networkView ownership to the person moving the object, meaning the person who isn't moving the object doesn't have ownership of it and just observes it's movement.
That's not necessary at all, RPCs do not depend on ownership. I suggest you take another look at the docs.
Your answer
Follow this Question
Related Questions
Is server the sender of RPC? 0 Answers
networkView.RPC() inside a ScriptableObject 1 Answer
Where is a free, helpful tutorial on how to use Unity's networking? 2 Answers
Which is better: NetworkView or RPC? 1 Answer
RPCMode.All Question 1 Answer