Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    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 .