Material.SetColor only works in Start function?
Hey guys,
I am making a virtual mixing console. Currently I am trying to change the color of a certain channel fader when the user presses the appropriate key (1 for channel 1, etc).
I start by declaring my Materials (one for each fader):
public Material fader1Material;
public Material fader2Material;
public Material masterMaterial;
Then initializing them as white:
//Initalize Fader Colours
masterMaterial.SetColor("_Color", Color.white);
fader1Material.SetColor("_Color", Color.white);
fader2Material.SetColor("_Color", Color.white);
However, if I alter the Material's color anywhere outside of the start function, it does not change color (This is in update):
if (Input.GetKey(KeyCode.Alpha1))
{
fader1Material.SetColor("_Color", Color.black);
ChangeChannel(1);
}
It does not throw an error, just doesn't work as intended. Pressing '1' successfully calls ChangeChannel(), but the color fails to change.
Any help would be appreciated!
Answer by Maxence_Marchand · May 23, 2018 at 10:46 AM
This is really strange... I tried to replicate your problem, but got no problem... Are you sure your material is assigned to your script (check in the Inspector, you should have something like this :
This is the only thing I can tell, hope it helps.