- Home /
RPC calls client to server Errors
Hi, I'm very confused here, just trying to understand the basics of how RPC calls work. But I'm having some errors, that in my point of view do not make any sense.
on my server i have an RPC function on a script attached to the main camera(only object on it):
[RPC]
void Register(string Username, string password)
{
PlayerPrefs.SetString(Username,Username);
PlayerPrefs.SetString(Username+"password", password);
}
on my client I have a GameObject made only for this inicial menu purpose, after i successfully connected to the server, i call the server RPC funtion:
GUILayout.Label("Username");
username = GUILayout.TextArea(username);
GUILayout.Label("Password");
password = GUILayout.TextArea(password);
if (GUILayout.Button("Register"))
{
if(Network.isClient)
{
networkView.RPC("Register",RPCMode.Server,username,password);
UI=1;
}
}
i get the error that the GameObject of the client does not have a function named "Register".... i do know that the client does not have this function, but why is this a problem?
RPC call failed because the function 'Register' does not exist in the any script attached to'GameObject'
UnityEngine.NetworkView:RPC(String, RPCMode, Object[])
StartClient:OnGUI() (at Assets/Client stuff/Scripts/StartClient.cs:148)
Answer by Aria-Lliane · Aug 17, 2013 at 05:53 PM
Makes no sense at all, just added this:
[RPC]
void Register(string Username, string password)
{
}
to the client side(yes, an empty function) for it to stop giving stupid errors and now works good, but it is so ....!
Correct, you have to pointlessly add an "empty" function on the sending side.
The documentation for NetworkView says that the overloaded version which takes the RPC$$anonymous$$ode parameter sends the RPC to all connected players, while the one with the NetworkPlayer parameter send it only to the target. Have you tried if the error appears with the NetworkPlayer one?