I
I
Ivan Ivanov2021-09-20 20:21:14
Unity
Ivan Ivanov, 2021-09-20 20:21:14

Why does the serialization of Vector3 and the like in the unit not work?

There is a class whose object I need to save to a binary file. For a field class of type float (saves normally), and types Vector3, Quaterion, Matrix4x4, etc. (does not save them) writes an error: "SerializationException: Type 'UnityEngine.Vector3' in Assembly 'UnityEngine.CoreModule, Version=0.0.0.0, Culture =neutral, PublicKeyToken=null' is not marked as serializable."
This is how I save:

FileStream fs = new FileStream("DataFile.dat", FileMode.Create);
Binary.BinaryFormatter formatter = new BinaryFormatter();
formatter.Serialize(fs, obj);
fs.Close();

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
freeExec, 2021-09-20
@freeExec

It's written there in black and white

is not marked as serializable

That is, if on the fingers, the class is not marked. [Serializable]
Although the unit itself serializes them into yaml, it probably has a custom serializer for these types.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question