- Home /
Instantiating Material Error?
Hi,
I've written a script that is supposed to make tiling materials easier. I was tired of constantly re-adjusting the tiling settings of materials on my walls as I resized them.
 [ExecuteInEditMode]
 public class AutoTiler : MonoBehaviour
 {
     public float xScaleMult = 1;
     public float yScaleMult = 1;
     private Material texture;
 
     // Update is called once per frame
     void Update()
     {
         if (!texture)
         {
             texture = GetComponent<MeshRenderer>().material; //get the material if it is null
         }
         
         //set the material scale based on the size of the object
         texture.mainTextureScale = new Vector2(Mathf.Max(transform.localScale.x, transform.localScale.z) * xScaleMult, transform.localScale.y * yScaleMult);
     }
 }
However, every time I reload the scene, I get an error message saying:
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.
I've looked up this error but I can't quite figure out how to solve it. I understand that I'm copying the material in order to change it, but that is the desired result. I don't want to change the material for every object, I just want to change it for every wall. Currently the code works, but fills the console with this error message. Is there a better way to do this, or barring that, a way to disable this error message?
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                