Scripts not updating the material's shader properties

Hello, I have a list of GameObjects and their materials that I’m trying to apply changes to via C# scripts.

I run this function every Update()

void Warp() {
        foreach (GameObject obj in Objects)
        {
            obj.GetComponent<MeshRenderer>().sharedMaterial.SetVector("Offset", new Vector4(-10, 50, 30, 40));
            Debug.Log(obj.GetComponent<MeshRenderer>().sharedMaterial.name);
        }
    }

According to my debug logs, it’s affecting all of the GameObjects in the list properly, yet when I run it there are NO noticeable changes to the Offset vector in the game AND in the inspector.

This topic seems to explain the same issue, and a comment there suggests that it has to do with the inspector dictating the values in the shader instead of the script. However, when I close the inspector, nothing happens still.

Any ideas on why this happens?

In this case you should use a for loop instead of a foreach

The foreach will take an element and this will be used as a temporary variable

for(int i = 0; i <= Objects.lenght -1; i++)
{
             Objects*.GetComponent<MeshRenderer>().sharedMaterial.SetVector("Offset", new Vector4(-10, 50, 30, 40));*

Debug.Log(Objects*.GetComponent().sharedMaterial.name);*
}
This should work I think :smiley: @bradyw24