Search Unity

Serialization Question

Discussion in 'Scripting' started by MrMetwurst2, Sep 7, 2013.

  1. MrMetwurst2

    MrMetwurst2

    Joined:
    Jul 16, 2009
    Posts:
    253
    Hey guys,

    Starting to finally get my head around serialization.
    Quick question.

    Can I serialize a List of Arrays?

    e.g. I have this under my class...

    Code (csharp):
    1. public List<byte[]> pattern = new List<byte[]>();
    and I create a few new lists of bytes under condition.

    Whenever I edit my scripts though the List is cleared. So I'm assuming either lists of arrays aren't serialized or Lists in general.

    Are Arrays of Arrays serializable because I can change my code to suit.

    Cheers.
     
  2. MrMetwurst2

    MrMetwurst2

    Joined:
    Jul 16, 2009
    Posts:
    253
    Never mind, I worked it out!
    Had me stumped for days and a little bit of extra research is all it needs sometimes :D

    For those interested I created a serialized class of the byte arrays and then I add the class to the list instead of an unserialized array which is what I was doing before.

    Code (csharp):
    1.     [Serializable]
    2.     public class newPattern
    3.     {
    4.         public byte[] patterByteArray;
    5.     }
    6.    
    7.     [SerializeField]
    8.     public List<newPattern> pattern = new List<newPattern>();