I have come across a small problem I don’t understand:
I have a full-screen quad, which can be set to any color. It is drawn last (via a camera set up for this purpose) creating an overlay of solid or semi-transparent color over the scene. The quad’s color is changed by changing the color assigned to the material:
public void SetColor(Color color)
{
OverlayMaterial.color = color;
}
In the Awake() method, the color of the material is set by calling SetColor(Color.clear). Works a charm (as does setting it to any other initial color).
In a coroutine in another class (started from that class’ Start() method) I call SetColor(Color.black) on the GameObject with the quad.
The weird thing is, it doesn’t work UNLESS I yield a frame BEFORE calling SetColor(Color.black). Without the yield the material’s visual appearance doesn’t change. With the yield, it works perfectly.
I’d like to understand why this happens so I can hopefully avoid similar mistakes in the future, because this took me ages to solve. Any ideas?