I have a large number of assets, all with multiple materials that I generate on the fly. I’d like to save these materials to disc (basically caching them). I’m doing all of this in the editor - in the end game, I’d just like to swap materials around, not generate and manually load textures.
So my question is - how do you save a material? Is it as simple as a binary serialization of the object to a “.mat” file?
edit: no, you can’t serialize it. (not marked as serializable). With that said, anyone know a way to save a dynamically create material?
Ohhhhhh, I think I understand your question now. You’ve created a material in the editor and you’re trying to figure out how to save it to a .mat file?
If you don’t want to have hundreds of files, then I think it should also be possible to save multiple materials into a single .asset file using AddObjectToAsset. I’ve not tried that though.
Hi all bellow is my code that basically allows me to add four material to a game Object, I assign the method NextColor() to a button to move the materials forward and the method RevertColor to moved back, given the effect of changing colour to the game object, everything works fine! My question if someone has the knowledge to help me pls, I need to save the new material, so whenever I start the game the last material chose stills there, and save me the time to pick the material again. Many Thanks
{
public Material[ ] material;
public int x;
Renderer rend;
// Start is called before the first frame update
void Start()
{
x = 0;
rend = GetComponent();
rend.enabled = true;
rend.sharedMaterial = material[×];
}
// Update is called once per frame
void Update()
{
rend.sharedMaterial = material[×];