I know you can use attributes to specify which fields/properties should be included for serialization, but since I don’t own this type that doesn’t seem like a viable approach.
Is anyone using JSON.net to serialize just the xyx components of vector3? If so how?
In Unity 2020.1 Alpha, I managed to get Newtonsoft.Json through the Unity package manager. I customized its serialization by inheriting from DefaultContractResolver and creating a JsonConverter.
The custom DefaultContractResolver makes the serialization work just like Unity’s serializer.
The JsonConverter gives us the power to decide how many decimal places ALL floats will serialize with.
I describe it and posted the code on the Unity forums.
Not sure if the OP found a solution, but I was getting this same error. I decided to just create a Vector3Json object with just x, y, z properties. When saving the objects, I would create this object from the Vector3 and serialize.
public void Awake()
{
SurrogateSelector surrogateSelector = new SurrogateSelector();
surrogateSelector.AddSurrogate(typeof(Vector3), new StreamingContext(StreamingContextStates.All), new Vector3SerializationSurrogate());
surrogateSelector.AddSurrogate(typeof(Vector3Int), new StreamingContext(StreamingContextStates.All), new Vector3IntSerializationSurrogate());
Helper.BinaryFormatter.SurrogateSelector = surrogateSelector;
}