- Home /
Question by
Borzen · Jun 04, 2013 at 05:36 PM ·
crashserialization
Unity crashing when serializing a list using XML
Unity keeps crashing when I want to serialize a list of some object. I thought it might be because Vectors are not seralizable but after creating a custom class to handle that problem it still crashes. The part where it crashes is when I call the serialization. Right now I have
Custom object to handle vectors
public struct HmSerilizer{
public float x,y,height;
public HmSerilizer(float a, float b, float c){
x = a;
y = b;
height = c;
}
}
List
[XmlArray("Heights"),XmlArrayItem("Height")]
public List<HmSerilizer> hmList{
get{
for(x = 0; x < hmWidth; x++){
for(y = 0; y < hmHeight; y++){
hmList.Add(new HmSerilizer(x,y,hm[x,y]));
}
}
return hmList;
}
set{
hm = new float[hmWidth,hmHeight];
for(x = 0; x < hmList.Count;x++){
hm[(int)hmList[x].x,(int)hmList[x].y] = hmList[x].height;
}
}
}
XML saving part
public void Save(){
FileStream fs = new FileStream("C:\\Users\\Borzen\\Desktop\\save.xml",FileMode.Create);
XmlSerializer xs = new XmlSerializer(typeof(SFField));
xs.Serialize(fs,this);
fs.Close();
}
let me know if I can be of any help to try to solve this problem.
Comment