Load, Edit and Save materials at runtime
Hello! I have a problem. I have a set of 3 materials called "0", "1" and "2". These materials need to be changed across about 18000 objects that each have one of these 3 material. I would like to want to edit the color/values of the material asset at runtime. Each level generates random colors for each of the 3 materials. Is there a way to do so without accessing sharedMaterials of a single mesh?
Here's what I have gotten so far.
Material new_material = (Material) Resources.Load("Materials/Tiles/0/0", typeof(Material));
Color new_color = new Color(
UnityEngine.Random.Range(0, 255),
UnityEngine.Random.Range(0, 255),
UnityEngine.Random.Range(0, 255)
);
new_material.SetColor("_BaseMap", new_color);
Comment
Answer by lgarczyn · Dec 22, 2019 at 06:57 PM
If all of these objects are already assigned to one of the three materials, simply editing the sharedMaterial of one of each of the three groups will update them all.
Do you need something more complicated than this?