We have a custom asset type, “AnimSet”, that store references to sprites. We also have a sprite-labelling system set up to work around the weird way unity stores sprites: We have a custom “SpriteIndex” asset which keeps track of each sprite’s virtual label. Ideally, we’d like to just store the “label” of a sprite in our AnimSet files. That way, we can change which sprite has a specific label, and have the AnimSet object update automatically in the editor (or at least after re-importing the custom asset).
Initially, I was hoping that on de-serializing an AnimSet from its file, Unity could check the stored label, and then load the appropriate sprite into a matching sprite field in the AnimSet’s object file. However, if I implement and alter ISerializationCallbackReceiver’s OnBeforeSerialize and OnAfterDeserialize methods in my AnimSet, won’t this also change how it gets used in a scene? If I have an object that references this AnimSet in my scene, I don’t want it to serialize the sprite back to a label, and then to a sprite when loaded. More strictly, I don’t want to include my SpriteIndex asset in our build at all. It’s really only meant as a means of storing sprites as strings in files, it shouldn’t affect runtime at all. But I can’t figure out how to de/serialize my AnimSets one way when storing/loading from file, and another way when referenced in a scene at runtime.
I am very open to any suggestions. I am not completely locked into this design pattern, it’s just my best attempt so far. Ideally I’d like to use this method, but if there’s something major I’ve missed I’d love to know about that as well. I am only somewhat comfortable with how Unity handles its asset files. As an added bonus, if someone who knows more could confirm/deny that this system will mesh well Unity’s AssetBundles, that would be appreciated. This system might be used on mobile, or on systems where we’d rather be updating installs with bundles, rather than having the user re-download an updated build from scratch.
I can clarify anything about this that wasn’t clear as well.