I am trying to change the material of a game objects renderers and then revert it back upon task completion but it is not working
MeshRenderer[] mesh = interactObject.GetComponentsInChildren<MeshRenderer>();
List<Material> meshSave;
foreach (MeshRenderer render in mesh)
{
meshSave.Add(render.material);
render.material = interactMaterial;
}
I get an error on meshSave.Add(render.material); saying that NullReferenceException: Object reference not set to an instance of an object. The code above is setting the original material into a list to then reference again when I want to revert the material back to its original. And then it takes each MeshRenderer and sets it to the new material called “interactMaterial”.
I tested it and the only thing that is not working is saving the original material into the list