As part of a custom mesh script, in edit mode, I have a menu item that creates an empty game object to host the custom mesh component as well as adds a MeshFilter and a MeshRenderer.
GameObject go = new GameObject();
go.name = "Expandable Plane";
go.AddComponent("MeshFilter");
go.AddComponent("MeshRenderer");
However, the MeshRenderer has no materials or sharedMaterials set on it. When I manually create primitives like cubes or spheres, the MeshRenderer automatically has the Default-Diffuse material applied. I’d like to apply this to my MeshRenderer, but am struggling to actually find the material using an Editor script.
GameObject.Find("Default-Diffuse");
Turns up null, so does:
Shader.Find("Default-Diffuse");
I know there’s a “Diffuse” shader that I could make a new material instance of, but I want to use the Default-Diffuse material as a sharedMaterial to avoid leaks.
My current hack solution is to temporarily create another primitive (plane, cube, whatever) and get the Default-Diffuse material from its sharedMaterial and apply it to my new object.