Search Unity

Third Party Photon Serialization Error!!

Discussion in 'Multiplayer' started by dick, Jun 12, 2017.

  1. dick

    dick

    Joined:
    Sep 6, 2014
    Posts:
    91
    Hello, when trying to serialize my Vector3i class in photon, I still get the error, Exception: cannot serialize(): Vector3i. Any Tips?

    Here's what i do to serialize it :


    Code (CSharp):
    1. using ExitGames.Client.Photon;
    2.  
    3. void Start()
    4. {
    5. PhotonPeer.RegisterType(typeof(Vector3i), (byte)'V', SerializeVector3, DeserializeVector3);
    6. }  
    7. public static readonly byte[] memVector3 = new byte[3 * 4];
    8.  
    9. private static short SerializeVector3(StreamBuffer outStream, object customobject){
    10.         Vector3i vo = (Vector3i)customobject;
    11.  
    12.         int index = 0;
    13.         lock (memVector3)
    14.         {
    15.             byte[] bytes = memVector3;
    16.             Protocol.Serialize(vo.x, bytes, ref index);
    17.             Protocol.Serialize(vo.y, bytes, ref index);
    18.             Protocol.Serialize(vo.z, bytes, ref index);
    19.             outStream.Write(bytes, 0, 3 * 4);
    20.         }
    21.  
    22.         return 3 * 4;
    23.     }
    24.  
    25. private static object DeserializeVector3(StreamBuffer inStream, short length)
    26.     {
    27.         Vector3i vo = new Vector3i();
    28.         lock (memVector3)
    29.         {
    30.             inStream.Read(memVector3, 0, 3 * 4);
    31.             int index = 0;
    32.             Protocol.Deserialize(out vo.x, memVector3, ref index);
    33.             Protocol.Deserialize(out vo.y, memVector3, ref index);
    34.             Protocol.Deserialize(out vo.z, memVector3, ref index);
    35.         }
    36.  
    37.         return vo;
    38.     }

    ANY HELP WILL BE GREATLY APPRECIATED!!