- Home /
Sending RPC to a specific client
I have a gameobject called "GlobalChat" that has a networkView attached and a Chat script that has lot of RPC functions, anyway a specific RPC function is targted to a client (the receiver of the chat entry) but when this RPC function is invoked i keep getting this two errors :
View ID SceneID: 0 Level Prefix: 0 not found during lookup. Strange behaviour may occur
and
Could't invoke RPC function 'functionName' because the networkView 'SceneID: 0 Level Prefix: 0' doesn't exist
so how can i solve this problem, i only want to call the rpc function to the specific client and this error is preventing from doing this ?!
here is a sample of the rpc function that is never called due to this error, hint: this part of code is from Chat script that is attached to an empty game object with networkView and has a scene id (not insantiated)
// This function is called on the client when the client OnMouseDown() another player
public void UpdateReceiverInfo(int _senderId, NetworkPlayer _receiver)
{
// create a receiver data structure and store receiver info
int key = int.Parse(_receiver.ToString());
if (!receivers.ContainsKey(key)) // if the key doesn't exist in the receiver array, then add the receiver and add a chat entries associated with it
{
// Add an entries list to this specified new receiver
ArrayList entries = new ArrayList(); // holds the text entries written by the connected players
entriesArr.Add(key, entries); // add this entries list to the entries arr
Receiver r = new Receiver();
r.receiverId = NetworkUser.clients[key].id; // retreive the receiver id from the static clients array
r.receiverName = NetworkUser.clients[key].name; // retreive the receiver name from the static clients array
r.receiverPlayer = _receiver; // retreive the receiver player from the static clients array
receivers.Add(key, r); // append the receiver data stucture to the receivers list
}
activeRIndex = key; // set the active client that we are currently chating with
// update the sender info to the receiver
networkView.RPC("ReceiveUpdateReceiverInfo", _receiver, _senderId, _receiver);
}
// This function is sent from a specific client that will receive the chat entry from the sender
[RPC]
void ReceiveUpdateReceiverInfo(int _receiverId, NetworkPlayer _sender)
{
print("Entered [RPC] ReceiveUpdateReceiverInfo"); // ERROR: This line is never executed becuz of the error
// This function is sent to the receiver client, in this case swap the process and convert the sender as receiver
int key = _receiverId;
if (!receivers.ContainsKey(key)) // if the key doesn't exist in the receiver array, then add the receiver and add a chat entries associated with it
{
// Add an entries list to this specified new receiver
ArrayList entries = new ArrayList(); // holds the text entries written by the connected players
entriesArr.Add(key, entries); // add this entries list to the entries arr
Receiver r = new Receiver();
r.receiverId = NetworkUser.clients[key].id; // retreive the receiver id from the static clients array
r.receiverName = NetworkUser.clients[key].name; // retreive the receiver name from the static clients array
r.receiverPlayer = _sender; // retreive the receiver player from the static clients array
receivers.Add(key, r); // append the receiver data stucture to the receivers list
}
activeRIndex = key; // set the active client that we are currently chating with
}
Are you sure you're calling it on the correct object? That it has a networkView attached? That the player is connected to the server?
A look at your script could probably help shed more light on this.
yes im calling the correct object its by the way a scene object in all players (server and client) and the players is connected to the server and this empty go has a network view with scene id, and i updated the post to include the rpc function that is never called u can look at the code.
So basically, the printf never happens?
Also, I'm not entirely sure if it has to do with this or not, but aren't you supposed to use: _receiver.networkView.RPC("ReceiveUpdateReceiverInfo", _receiver, _senderId, _receiver); on line 24?
_receiver is a NetworkPlayer instance which represents the client tht will receive the chat entries and it hasn't a networkView attached ! but thx anyway for the reply
Answer by Omar47i · May 11, 2014 at 12:50 PM
After stumbling a long time i discovered where is the problem, and i dont know y this but it seems that a connected client can't send an RPC function directly to another connected client ! i must first send it to the server and then the server will forward it to the target client, even if the client has the networkPlayer of the target client !!
Your answer
Follow this Question
Related Questions
Overloading RPCs 1 Answer
networkView not called on Child objects? 0 Answers
Networking Error! 0 Answers
OnSerializeNetworkView issus in my 2D game 3 Answers
Couldn't invoke RPC to server after Network.Destroy 0 Answers