- Home /
Sending Data through RPC
Hello, some reason If I understood the page for rpc's correctly, you should be able to send certain kinds of data to other clients or servers, (int, float, string) but some reason when I try to send the data to the other clients and server, it completely ignores to tell everyone the max players for the game.
Here is my code example
void OnPlayerConnected()
{
networkView.RPC("AddPlayer",RPCMode.AllBuffered,TotalPlayers);
}
void OnPlayerDisconnected(NetworkPlayer aPlayer)
{
networkView.RPC("RemovePlayer",RPCMode.AllBuffered,TotalPlayers);
Network.RemoveRPCs(aPlayer);
Network.DestroyPlayerObjects(aPlayer);
}
and these are the RPC's that I'm calling when the player connects or disconnects
[RPC]
void AddPlayer(int Total)
{
TotalPlayers = Total + 1;
Debug.Log("Sent"+TotalPlayers);
}
[RPC]
void RemovePlayer(int Total)
{
TotalPlayers = Total - 1;
}
is there something I'm doing wrong or missing or does there seem to be a bug. I've been trying to do this for awhile now and help on this if its impossible or something I'm not doing correctly
Answer by Guardian2300 · Apr 02, 2014 at 05:20 PM
Solved the string array also, I created one string from the array of strings and sent into the rpc string variable i created and then I split them up after they were retrieved.
Answer by paskal007r · Mar 15, 2014 at 06:17 PM
Did you check that the RPC is actually sent?
Most of the times I had a similar problem it was because of issues with the networkview (networkViewId not matching on objects generated at runtime on different instances or no networkview attached to the object at all).
Also, are the rpc's and the onPlayerConnected on the same object? If not the problem might be that you should call the rpc on the networkview of the object with the rpc functions.
I solved it but now another question with sending data through rpc, is it possible to send a string array through the rpc function?
Your answer
Follow this Question
Related Questions
Networking When Offline 1 Answer
Which is better: NetworkView or RPC? 1 Answer
RPC failed to send 1 Answer
Photon Network Instantiate Objects over Network 1 Answer
unity c# RPC 0 Answers