Hi there…
I am trying to automate some character set-up stuff in Unity.
I’ve written a script that does most of the work.
However, I am struggling to set the Materials on my MeshRenderer.
The code:
//Set the materials
Material characterMaterial = AssetDatabase.LoadAssetAtPath<Material>("Assets/00 - Thunderbox/Materials/Characters/Characters(Teleport).mat");
Material lightMaterial = AssetDatabase.LoadAssetAtPath<Material>("Assets/00 - Thunderbox/Materials/Environment/Light Pattern Faster.mat");
crewMesh.sharedMaterials[0] = characterMaterial;
if (crewMesh.sharedMaterials.Length > 1) crewMesh.sharedMaterials[1] = lightMaterial;
This looks pretty legit… I am using the shared materials, so it should be OK…
WRONG!
The script doesn’t assign the materials, and, instead, throws up this error…
Instantiating material due to calling renderer.material during edit mode. This will leak materials into the scene. You most likely want to use renderer.sharedMaterial instead.
UnityEngine.Renderer:get_materials()
initCharacter:Execute() (at Assets/00 - Thunderbox/Scripts/Editor/initCharacter.cs:29)
… but I am indeed calling the shared material!!!
I’ve searched the web for hours for a solution, but no joy. Any ideas would be most appreciated. Thanks!