Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only. On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live. Read our full announcement for more information and let us know if you have any questions.

Bitstream.Serialze in C#

Discussion in 'Multiplayer' started by AmazingRuss, Jul 29, 2008.

  1. AmazingRuss

    AmazingRuss

    Joined:
    May 25, 2008
    Posts:
    933
    This is a method in my MonoBehaviour class:
    Code (csharp):
    1.  
    2. void OnSerializeNetworkView(BitStream stream, NetworkMessageInfo info)
    3. {
    4.     int s = 999;
    5.     print("sending 999");
    6.     stream.Serialize(s);
    7. }
    Unity is treating the int (and all the other types I tried) as a bool, and then complaining about an invalid argument. Does anybody know how I need to call Seriaize in C#?
     
  2. Der Dude

    Der Dude

    Joined:
    Aug 7, 2006
    Posts:
    213
    This happens if you don't pass the variables with the ref keyword. The topmost error in the console should say this.

    So you need to write:

    Code (csharp):
    1.  
    2. stream.Serialize(ref s);
    3.  
     
  3. AmazingRuss

    AmazingRuss

    Joined:
    May 25, 2008
    Posts:
    933
    Thank you. I was trying to use .