I have created a simple color swap shader, and then a material from it. Now, I would like to see the effect in action in Edit Mode.
However, I receive the following 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.
I do not want to update the sharedMaterial, because I want to be able to set different colors for different game objects, and using that property would change the value in the base material, which I do not want.
What do I need to change to address the error, please?
Here's my script:
[ExecuteInEditMode]
public class ColorSwap : MonoBehaviour
{
[SerializeField] private Color color;
private SpriteRenderer spriteRenderer;
private void Awake()
{
spriteRenderer = GetComponent<SpriteRenderer>();
}
void Start()
{
spriteRenderer.material.SetColor("color", color);
}
}