- Home /
The question is answered, right answer was accepted
How do I Serialize an imported asset?
Since Unity doesn't use the ISerializeable interface to serialize and deserialize classes, (At least it doesn't seem to for custom classes), how can I serialize a runtime Unity class so I can store it and load it later from a binary stream? In particular, fonts, atlases and GameObject prefabs.
I need to deserialize at runtime but I'm fine with serializing in the editor. I wish they had GetObjectData() :P
Well there's my Unity Serializer (also on the Asset Store) that will save many things - but not custom fonts (it would save the fonts you'd applied to something, but not the actual font textures). It can rebuild an object from basic components like a prefab etc.
What I sometimes do is use that to create a byte[] which I embed in a normal object and load it from there - or you could just make a file etc.
Answer by MartinCA · Apr 15, 2013 at 09:30 PM
Just out of curiosity - what is the use case you intend for that feature?
Unity already serializes interally all imported assets and bundles them by scene reference. If you would like to have assets available at runtime without any scene dependency, you can use Unity's Resource pipeline.
In addition to bundling assets by scene, unity also serializes all supported* asset types in your Resources folder, which you can then load at runtime using Resources.Load(). And, well, anything which is not supported is probably not a MonoBehaviour, so you can implement ISerializeable yourself :P
Another existing solution ( which I have no experience with, I must admit ), is asset bundles. Might be worth giving that a reading.
Either way, it sounds like you are working to implement an already existing feature, I highly suggest you take a look at the Resource class documentation and see if it fits your need before reinventing any wheels :)
I want to embed assets in a dll as compressed binary files. In particular a list of prefabs and a GUISkin complete with fonts and have the whole thing compatible with Unity Free.
Are you trying to create a plugin, or is there a reason to obfuscate these assets? Because otherwise Resources does exactly that, only ins$$anonymous$$d of a dll, it serializes everything to proprietary format ( Unity's .sharedassets )
I though prefabs had metadata that was specific to the project that holds them? This is not exactly a plugin it's a general utility library that has to be portable across 7 projects.
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
Multiple Cars not working 1 Answer
Instantiate already connected players. 0 Answers
Making change to an instance of a prefab doesn't work... 1 Answer