Yarg Yarg - 3 years ago 177
C# Question

Is there a method that would be called right before the serialization of the object in Unity3D?

There is a class that have data that cannot be serialized easily. But, I can prepare it to serializable form.
So, is there any method to override that will be called right before serialization to prepare data?

public MyCalss {
//Unity can serialise this list;
public List<int> serializableData;

//class contains a lot of data that cannot be serialized by Unity3D

protected override void OnSerialize() { // <-- looking for this method
//pack all my data into the serializableData array

public Behaviour: MonoBehaviour {
MyClass instanceOfMyClass; // will be serialized by Unity3D

Answer Source
void OnBeforeSerialize()
void OnAfterDeserialize()

they exists in interface


so just implement this interface is ok

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download