I am trying to do an RPC call to the server and it’s not making it there.
I get the debug message from the player but not the server
Can someone please help me?
Here is the relevant portion of the player script which is a component of a gameobject which also has a networkview attached:
void Update() {
if (Input.GetKeyUp(KeyCode.Space)) {
Debug.Log ("Player - Call RPC");
networkView.RPC("Shoot", RPCMode.Server, selectedPlayer.transform.position, new Vector3(1f,1f,0f));
}
}
[RPC]
void Shoot(Vector3 pos, Vector3 vel, NetworkMessageInfo info) {
}
Here is the relevant portion of the network manager script:
[RPC]
void Shoot(Vector3 pos, Vector3 vel) {
Debug.Log ("SERVER SHOOT");
}
RPC functions must be unique. You can’t have two Shoot functions as only one of them will be called.
UL,
Thanks for the response.
However, if I remove the RPC method from the player object entirely, I get the “RPC call failed because the function ‘Shoot’ does not exist in the any script attached to’Player(Clone)'” error.
From the reading I did, I thought you HAD to have the exact same RPC method in the player and “server” code for it to work.
– Paul
Just to cover our bases does your network manager have a network view as well?
edit: also keep in mind that if you are playing as the server the function won’t execute. You would want to run the function locally instead.
Yes, but I’m not sure I did it correctly.
I have a networkmanager GO.
The networkmanager script and a network view are components of the GO.
Here’s a screen cap:
UL,
Thanks but, I want to use the RPC to have the server call Network.Instantiate().
If I can’t call an RPC, how do I implement that functionality?
EDIT: Would I have to have three instances of my app running around? One for server and two for the players?
– Paul
Sorry if my reply was confusing. What I meant was that if you try to execute an RPC call as the server it will never fire off the RPC function so you have to execute it like you would a normal function (Network.isServer will tell you if you are server or not). All other players would use the RPC call using RPCMode.Server
Here’s some psseudo code to explain it a little better:
void DoSomething() {
if (Network.isServer) {
Foo(1);
} else {
networkView.RPC("Foo", RPCMode.Server, 1);
}
}
[RPC]
void Foo(int aNumber) {
}
UL,
Thanks for that!
Another general question:
For purposes of doing a multiplayer game, do you think it’s best to architect it so that the server runs in it’s own instance and the players all connect as clients?
Would that make some coding issues cleaner with every player running as a client?
– Paul