Search Unity

uLink - RPC acceptable argument type

Discussion in 'Multiplayer' started by Zergling103, May 9, 2013.

  1. Zergling103

    Zergling103

    Joined:
    Aug 16, 2011
    Posts:
    392
    Hi there,

    I was wondering if the types outlined here:

    http://developer.muchdifferent.com/unitypark/uLink/Serialization

    ...Can be used as RPC arguments.

    For example, would the following work: (Assume everything is public.)

    Code (csharp):
    1. struct MyStruct {
    2.    int a, b, c;
    3.    float x, y, z;
    4.    int[] myIntArray;
    5. }
    6. ...
    7. networkView.RPC("MyRpc",
    8.     new MyStruct(...),
    9.     new int[] {1, 2, 3});
    10. ...
    11. void MyRpc(MyStruct myStruct, int[] intArray, uLink.NetworkMessageInfo info) {
    12.     ...    
    13. }
    Note that X is a struct, not a class. uLink mentions classes in #6 but not structs, I assume it doesn't care which one you use.

    Also, is the uLink.NetworkMessageInfo argument optional? Sometimes I don't use it, and I'd rather not include it when I don't use it as it makes the code a little uglier.

    Thanks for your help! :D
     
    Last edited: May 9, 2013
  2. Ashkan_gc

    Ashkan_gc

    Joined:
    Aug 12, 2009
    Posts:
    1,124
    Hi, First of all it's better to ask uLink related quesitons in forum.muchdifferent.com , secondly you are able to pass any struct/class if you write a serializer for it or if it only uses types which uLink can serialize as it's manual said. Vector3 is a struct for example which is supported by default so you can write your own structs and serialize them and send them. Most of the times writing your custom serialization code as described in manual is a good practice and helps you save bandwidth by not sending unrequired data.