serialize struct

As the topic says, how do i serialize a struct within photon. Is that even possible? I noticed "CostumTypes" code in the PUN package, but im not sure how to do this for struct.

Anyone knows?


  • You could indeed add your struct to the CustomTypes.cs:

    in Register()
    PhotonPeer.RegisterType(typeof(MyStructType), (byte)'Z', SerializeMyStruct, DeserializeMyStruct);

    Then also add the methods:
    private static byte[] SerializeMyStruct(object input){
    private static object DeserializeMyStruct(byte[] input){

    In these two functions you'll have to serialize your struct into an byte[] as shown for the other types.
  • Well, when i try to sync a object array with RPC, it seems that i have to add the amount of the array lenght to the rpc function parameters. How do i only collect the array instead of its unpacked?
  • would u like to example me how i should get photon to sync this struct?

    I dont know what to do inside the place where u have the //TODO
    public struct playerData {
    		public string name;
    		public int seatid;
    		public int money;

  • Sorry, we can't write your code. We did this with Vector3 and others in the PUN class CustomTypes. Look it up in the Unity project, then it will become obvious what to do.
Sign In or Register to comment.