Changing Texture On Collision

I’m trying to get an object that will follow a path and change a tiles texture to look like a road on the path it follows. Pathing is fine and I seem to be referencing the correct object on collision and debugging tells me I get to the proper code. However, the textures refuse to change. I can do it manually just fine but for some reason it won’t change at run time.

Here’s my code:

    public Texture roadTexture;
  
   
    public void OnTriggerEnter(Collider other)
    {
        if (other.gameObject.layer == 3)
        {
            Debug.Log(other.material);
            Debug.Log(other.gameObject.GetComponent<Renderer>().materials[0].mainTexture);

            other.gameObject.GetComponent<Renderer>().materials[0].SetTexture("_MainTex", roadTexture);
        }

    }

the other collider is in layer 3 and both debug logs run and show me I’m referencing the correct material (I also debugged object names and tags to make sure it was referencing the correct object too). Any help would be appreciated.

Oh my, don’t do stuff like this…

If you have more than one or two dots (.) in a single statement, you’re just being mean to yourself.

Putting lots of code on one line DOES NOT make it any faster. That’s not how compiled code works.

The longer your lines of code are, the harder they will be for you to understand them.

How to break down hairy lines of code:

http://plbm.com/?p=248

Break it up, practice social distancing in your code, one thing per line please.

“Programming is hard enough without making it harder for ourselves.” - angrypenguin on Unity3D forums

“Combining a bunch of stuff into one line always feels satisfying, but it’s always a PITA to debug.” - StarManta on the Unity3D forums

Also:

Materials materials array of materials renderer:

Generally accessing .material / .materials is going to give you a fresh copy. (See docs for why and when)

https://discussions.unity.com/t/789181/5

https://discussions.unity.com/t/826696/5