Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

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 .