I am trying to send an array of various basic types over the Network using the ClientRpc
attribute. The documentation states, that I can send these over the Network without problems:
- basic types (byte, int, float, string, UInt64, etc)
- arrays of basic types
However, it seems holding them mixed together in an object[]
array does not work. I have the following example:
[Command]
void CmdForwardEvent(string eventName, object[] args) {
Debug.Log ("Broadcasting event: " + eventName);
foreach (var o in args) {
Debug.Log ("arg-class: " + o.GetType() + ": " + o);
}
RpcForwardEvent (eventName, args);
}
[ClientRpc]
void RpcForwardEvent(string eventName, object[] args) {
Debug.Log ("Received event " + eventName);
foreach (var o in args) {
Debug.Log ("arg-class: " + o.GetType() + ": " + o);
}
}
void Update() {
if (Input.GetKeyDown (KeyCode.P)) {
CmdForwardEvent("Testevent", new object[]{"some string", 1, false});
}
}
On the server, I get the output
Broadcasting event: Testevent
arg-class: System.String: some string
arg-class: System.Int32: 1
arg-class: System.Boolean: false
On the client, this arrives without any errors:
Received event: Testevent
arg-class: System.Object: System.Object
arg-class: System.Object: System.Object
arg-class: System.Object: System.Object
How can I send various amounts of arguments with different basic types over a ClientRpc call?