We have certain base creatures in our game and variants that use different textures. I’m trying to create prefabs using editor scripts with the same mesh but with different materials/textures on each prefab variant.
However the material I create and instantiate does not seem to save into the prefab. It is lost each time I close unity. Is there a way to save a material onto a disk? Or modify the texture its pointing to?
// outside function:
Material newMaterial; // set through inspector
// inside a function
renderer.material = newMaterial;
hope that helped you out =)
I understand how you’d change the material in a renderer but in my case I’m trying to figure out how to save that material file:/
Hi
I’m doing something similar, that is using dynamic materials/textures. I ended up creating prefabs with scripts that contain references to the different materials and textures in arrays. I then use dictionaries to access those and set them to gameobjects dynamically.
One prefab would thus have several scripts attached. Each of those scripts would contain a list of materials and textures that could be applied to a game object.
Regards
/Klum
You need to use the renderer’s sharedMaterial property to make the changes permanent. See this manual page for more details.