I have a fadeout script to change the material properties when something blocks the screen. I want the objects to fade individually but when a new object fades, all the others also start the fade again or start fully faded out immediately.
The Docs say changing material properties using renderer.material
creates a new instance of the material, but the behaviour I see points to them still being the same instance.
The material is a simple unlit ghader graph and here’s the Coroutine
I use to fade the object:
IEnumerator TransitionTransparency ()
{
_renderer.material = _transparentMat;
float transition = 1;
while (transition > 0) {
_renderer.material.SetFloat("_Transition", transition);
transition -= Time.deltaTime / _transitionTime;
yield return null;
}
Destroy(_renderer.material);
_renderer.material = _transparentMat;
yield break;
}
Thanks, Tried it out and this solution works even without setting the override. I rewrote my code to use DOTween in the meantime (forgot I had it in the project) and for a single property it seems simpler. I suppose the upside of using your solution (apart from being what unity is pushing towards, I guess) is that fewer draw calls are made, so it definitely has merit when many objects are changed. Anyways, thanks for pointing out a feature I was unaware of.
– Lodestar