- Home /
Having problems using xml to serialize a Vector3 in a custom class
I have a custom class that has members for the gameobject, component, field/property, and value to store in an xml file. This way data can be loaded back into the correct field/property. It works until I try to serialze a Vector3. It gives an error saying that a Vector3 is not a primitive type and it fails to serialze the data. My newValue variable is of type "object" so that it can store different types of data. It is holding the Vector3 correctly, but it can't seem to serialze it. Now the strange thing is that if I declare a Vector3 variable before my newValue variable in the custom class, it will serialize newValue perfectly fine and load it back the next time the game is run. Why is having a Vector3 variable declared allowing it to serialize newValue as a Vector3? Is there some other way to let the serializer know that there might be a Vector3, using XmlType or something similar?
Your answer
Follow this Question
Related Questions
C#-XMLSerialize a Struct with Vector3 Array in it 2 Answers
Why does my vector3 inside a custom class not serialize? 0 Answers
What are the pros and cons of ScriptableObjects vs. JSON for data files? 2 Answers
Deserializing data with XML Serializer 0 Answers
Trying to XML serialize objects, getting error that UnityEngine.Transform doesn't implement Add() 1 Answer