Can Strings be safely sent in an RPC, or is there more coding required? DEBUGGING INFORMATION INCLUDED…
I send string, int, and float across network to clients via rpc call to all. They only recieve the values for float and int not the string value. I have confirmed this with numerous tests, rewrites and debug routines.
I can post my code but since what I’m doing is very simple I think this should suffice for now. All I am doing is using a RPC call to all and sending a string, float, and int, then reading it back from the client in a debug routine. Its important to note that the string that is sent is used to overwrite a string variable on all clients.
In the picture, server is on the right and client on the left - server typed a message to itself and client. Client reads the float and int, but not the String.
If you choose to answer please try to test this out by writing a simple RPC to send strings, then read back the change to the string variable from the client in a debug routine similar to what I have done. If you do not debug this it is going to be hard to solve.
RPC functions send/receive string parameters just fine for me. Per the docs, you can send only the following datatypes as RPC function parameters:
- int
- float
- string
- NetworkPlayer
- NetworkViewID
- Vector3
- Quaternion
Sending strings kind of works, if i send a string variable and rewrite a variable on the clients machine it does NOT work. just sending a string however does. Its funny ive been writing all of my own network code and i have never had this problem, im still having a really hard time with this guys…
I do not want to use sendmessage. My RPC looks like this:
if (Event.current.type == EventType.KeyDown && Event.current.character == '
’ && GUI.GetNameOfFocusedControl () == “Text1” ) {
textFieldOpen = false;
var sendString = (realPlayerName + " : " + stringToEdit) as String;
networkView.RPC ("chat", RPCMode.AllBuffered, "GENERIC TEST STRING = " + " TEST248 " + "SEND STRING = " + sendString, Time.time, Mathf.FloorToInt(Random.value * 20));
if (DEBUG) {
print ("chat rpc called" );}
}
////////////////////
@RPC function chat ( text : String , flVal : float, inVal : int) {
//if (levelNameString.Length > 280) {
//levelNameString = “”;
//}
debuggingFloat = flVal;
debuggingInt = inVal;
Debug.Log("RPC FUNCTION CHAT TEXT IS " + text);
Debug.Log("RPC FUNCTION CHAT TEXT IS " + text.Length);
chatMessages[4] = chatMessages[3];
chatMessages[3] = chatMessages[2];
chatMessages[2] = chatMessages[1];
chatMessages[1] = chatMessages[0];
chatMessages[0] = text;
}
@RPC function chat ( text : String , flVal : float, inVal : int) {
//if (levelNameString.Length > 280) {
//levelNameString = "";
//}
debuggingFloat = flVal;
debuggingInt = inVal;
Debug.Log("RPC FUNCTION CHAT TEXT IS " + text);
Debug.Log("RPC FUNCTION CHAT TEXT IS " + text.Length);
chatMessages[4] = chatMessages[3];
chatMessages[3] = chatMessages[2];
chatMessages[2] = chatMessages[1];
chatMessages[1] = chatMessages[0];
chatMessages[0] = text;
}