Changing the color of all instances of a material

I have a problem where I’m trying to change all the instances of a specific material’s color. Specifically, I want to lerp the colors on a material from it’s “daytime” color to it’s “nighttime” color. My first thought was to have a game object instance that does this:

[System.Serializable]
public class MaterialInformation
{
	public Material material;
	public Color nightMainColor;
	public Color nightEmissiveColor;
	internal Color dayMainColor;
	internal Color dayEmissiveColor;

	public void Initialize()
	{
		if( material )
		{
			dayMainColor = material.color;
			dayEmissiveColor = material.GetColor( "_Emission" );
		}
	}
	
	public void SetParametric( float t )
	{
		if( material )
		{
			material.color = Color.Lerp( dayMainColor, nightMainColor, t );
			material.SetColor( "_Emission", Color.Lerp( dayEmissiveColor, nightEmissiveColor, t ) );
		}
	}
}


public class DayNightCycleController : MonoBehaviour
{
	public MaterialInformation[] materialInformation;
	float tempTimeValue = 0.0f;
	
	void Start()
	{
		foreach( MaterialInformation mat in materialInformation )
		{
			mat.Initialize();
		}
	}
	
	void Update() 
	{
		tempTimeValue += Time.deltaTime;
		float currentParametric = 1.0f + ( 2.0f * Mathf.Cos( tempTimeValue ) ); // this gets clamped to [0,1] in Lerp
		
		foreach( MaterialInformation mat in materialInformation )
		{
			mat.SetParametric( currentParametric );
		}
	}
}

Which basically means you create an array of objects that points to a material and gets the color, then just sets the material’s main and emissive colors per what the inspector says. (The idea is that all the materials in the scene that would react to the day/night transition would have their own night time colors set here.)

The problem is that it’s the same side effect as using renderer.sharedMaterials in that when you, say, quit playing the game in the editor the colors at that point in time are now saved.

Is there any way to achieve the same effect without it blowing away the set colors in the editor or setting the values for each material on each game object in the scene individually?

I managed to do something that made it work, but something tells me there’s a much more efficient way of doing things…

in the MaterialInformation helper class

	public void SetColorOfMaterialForParametric( Material mat, float t )
	{
		mat.color = Color.Lerp( dayMainColor, nightMainColor, t );
		mat.SetColor( "_Emission", Color.Lerp( dayEmissiveColor, nightEmissiveColor, t ) );
	}

in Update on the manager script

		GameObject[] gameObjects = Object.FindObjectsOfType( typeof( GameObject ) ) as GameObject[];
		foreach( GameObject gameObject in gameObjects )
		{
			if( gameObject.renderer )
			{
				foreach( Material mat in gameObject.renderer.materials )
				{
					foreach( MaterialInformation matInfo in materialInformation )
					{
						if( ( matInfo.material.name + " (Instance)") == mat.name )
						{
							matInfo.SetColorOfMaterialForParametric( mat, currentParametric );
						}
					}
				}
			}
		}

The O(N^3) with a string compare really probably isn’t a good way of doing this.