What is the real purpose of ISerializationCallbackReceiver interface?

Hey everybody, asked this question about problems to instantiate a SO with a property that returns a dictionary and the guy who answered me, recommended the use use of ISerializationCallbackReceiver. So I started to implement it considering the example in the documentation. I’m kinda new to coding, but the example just converts the dictionary to a 2 lists and vice-versa, if I got the right idea about it…


In my implementation, I was thinking about use the convertion methods everytime I need to use a serializable type (2 lists) or the original type (dictionary), but something tells me that I’m missing something here. If this interface just converts the non-serializable type into a seriazable one, why this interface exists at all? I mean what’s the point to have an interface in the API if I can just create my own convertion methods instead of using it. Probably, Im not using it right, any thoughts?

The interface exists to receive the events that occur before unity serializes the data for the object, or after it is deserialized. It’s not to convert, it’s to give you events that you can convert during.

The conversion between dictionary and list is because Unity does not support Dictionary. So before serializing, you convert the dictionary into 2 lists, and then Unity serializes those.

And after deserialize, we build the dictionary out of the lists which unity just deserialized.