I’m trying to instance sprites right now, and I’ve written 2 lines of code that seem to pull this off, but only by sheer accident, and could be a bug in Unity.
using UnityEngine;
public class Sprite : MonoBehaviour
{
public Material SphereMaterial;
private void Awake()
{
GetComponent<SpriteRenderer>().material = SphereMaterial;
//If this debug is removed, the sprite is no longer instanced
Debug.Log(GetComponent<SpriteRenderer>().material);
}
}
With this code, during runtime I can change shader properties on the object without effecting the source shader. But, if I remove the Debug.Log line, it no longer behaves this way and changing the shader attached to the object will change the original shader. I’d hate to leave these worthless debugs in the code because they somehow give me the result I’m aiming for.