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?
Answer by lordofduct · Nov 24, 2018 at 09:37 PM
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.
Thanks for the answer man, I'm feeling a little dumb cause it isn't clear enough for me. Here's an image for my "Serializer" class, where I'm trying to use that interface:
I'm probably building this wrong, telling this cause the way I'm thinking right now, the interface would be used as a "converter". I believe that you can understand my thought by the image, let me know if you dont. $$anonymous$$y way just doesn't seem right and I'm stucked because of that. I would like to see a broader example or something...
Your answer
![](https://koobas.hobune.stream/wayback/20220612182658im_/https://answers.unity.com/themes/thub/images/avi.jpg)