executing .Apply on 1 texture affects many RawImages , not just 1

I have 3 RawImages on 1 canvas. I want to put a different Texture2D on each RawImage. I seem to be required to .Apply() on my various Texture2Ds but then the last Texture2D I .Apply()'d to now shows up on the screen in all 3 RawImages. If I don’t call .Apply at all then the Texture2D’s don’t show up in the display.
The code looks something like this:

       Texture2D tex1 = null, tex2 = null, tex3 = null;
       tex1 = new Texture2D(200, 200);
       tex2 = new Texture2D(200, 200);
       tex3 = new Texture2D(200, 200);
       GameObject Projection1,Projection2,Projection3;
       for (int i = 0; i < 200; i++)
              {
                 for (int j = 0; j < 200; j++)
                       {
                            tex1.SetPixel(i,j,the new color);
                        }
               }
      Projection1.transform.GetComponent<RawImage>().material.mainTexture = tex1;
      tex1.Apply();
      for (int i = 0; i < 200; i++)
            {
                 for (int j = 0; j < 200; j++)
                        {
                             tex2.SetPixel(i, j, the new color);
                        }
              }
      Projection2.transform.GetComponent<RawImage>().material.mainTexture = tex2;
      tex2.Apply();
      for (int i = 0; i < 200; i++)
              {
                        for (int j = 0; j < 200; j++)
                        {
                             tex3.SetPixel(i, j, the new color);
                        }
                }
      Projection3.transform.GetComponent<RawImage>().material.mainTexture = tex3;
       tex3.Apply();

The RectTransforms which set the size of the RawImages sets all 3 RawImages to size 200 by 200 (there’s no mismatch there). If I don’t ever make a call to .Apply then all the RawImages are grey squares. When I call .Apply multiple times then whatever the last call was apparently overrides the others and writes THAT Texture2D to all 3 RawImages. I wind up seeing 3 copies of the last Texture2D that I call .Apply on. ???

The RawImage doesn’t have the same auto instancing mechanic that a normal Renderer has. A Renderer has a material and a sharedMaterial. Whenever you access material on a Renderer you automatically create an instance of the sharedMaterial which is now used by this renderer.

The RawImage does only have a reference to “a” material. When you change the texture of the material, all your RawImage components will use / reference the same material.

You shouldn’t mess with the material of the RawImage. I haven’t really used the RawImage component but you most likely should assign your texture to the texture property of the RawImage component and not altering the material it uses.

If this doesn’t work for some reason you may need to use seperate materials for each RawImage component. However due to the fact that the RawImage component has a seperate texture property i guess that’s not necessary.