Hi, In my game I’m attempting change materials on an object but am running into a strange issue. When I run the game inside the editor everything works as expected, however, when I make a build, all objects using the Toon/Basic Outline shader (part of the effects package in standard assets) turn bright pink. I’ve noticed that the build will work correctly if I only include one object that has the material changing script attached to it.
Here is the material changing script, it’s loosely based off the Render.material example provided at Unity - Scripting API: Renderer.material :
public class MaterialManager : MonoBehaviour
{
public Material normalGhostMaterial;
public Material lightGhostMaterial;
public Material darkGhostMaterial;
public float runForSeconds = 5;
private Renderer rend;
private float timer = 0;
private float blinkInterval = 0.4f;
private float lastBlinkTime = 0f;
private int blinker = 1;
void Start()
{
rend = GetComponent<Renderer>();
rend.enabled = true;
}
void Update()
{
checkTimesUp();
}
public void startRunning()
{
rend.material = darkGhostMaterial;
startTimer();
}
void startTimer()
{
timer = Time.time;
}
void checkTimesUp()
{
if (Time.time - timer > runForSeconds)
{
rend.material = normalGhostMaterial;
blinker = 0;
}
else
{
if (Time.time - timer > 2.5f && Time.time - timer < runForSeconds && Time.time > 5)
{
blink();
}
}
}
void blink()
{
if (blinkTimeChange())
{
blinker++;
}
if(blinker % 2 == 0)
{
rend.material = lightGhostMaterial;
}
else
{
rend.material = darkGhostMaterial;
}
}
void startBlinkTime()
{
lastBlinkTime = Time.time;
}
bool blinkTimeChange()
{
if (Time.time - lastBlinkTime > blinkInterval)
{
startBlinkTime();
return true;
}
else
{
return false;
}
}
}
I noticed in the sample on the render.material page that they use rend.sharedMaterial instead of rend.material. I tried this but it didn’t fix anything. I’ve also tried the script with the Unlit/Color shader and it seems to work fine with that, but I’d still prefer to use the toon shader. At the moment, the materials I’ve created (with the issues) use a ‘Toon/Basic Outline’ shader with just the ‘Main’ and ‘Outline’ colors defined. There are options for 2D textures but I’ve left them set at ‘None’ (which has been working fine up till this issue). Anyway, as always, thanks for your time and words of wisdom!