- Home /
Load material from serialized text (from StreamingAssets)
How can I go about converting a material as a text file to a usable in-game material at runtime?
I want to save and load .mat materials to StreamingAssets (Windows) at runtime. Saving works fine, I'm having trouble converting a .mat file back into an actual material.
For example, this is what you get if you just change a default New Material to a .txt file. Reading any file as string text in Unity is easy, I'm not sure how to convert it to an actual material though.
I'd really rather not have to manually parse and convert the entire text file! This approach would likely be infeasible too, since I'd like to allow players to mod in their own content (custom materials, shaders, whatever) and I may not have all the values ready to parse.
Edit note: I looked into AssetDatabase.CreateAsset but it's Editor only, this needs to work at runtime. Also, AssetBundles don't work for this project as I want to store the files themselves, not bundles. For some types like 3D models special importers like TriLib work great, but for more generic unity-centric things like materials I need to convert the text to asset at runtime.
Thank you!