title: How to set texture of shader graph material via script with URP
body: <p>I am trying to set the texture of a shader graph material and am having no luck. After following some tutorials and some googling I can't seem to get it working.</p>
  
  <p>So far I have set my scene up with a plane i generated via code and a pre-built one and have applied the material to both of these. I then created a script to set the texture of the MeshRenderer to "_MainTex" as I saw mention several times while googling. I also set the material texture property to "_MainTex".</p>
  
  <p>I also tried the Reference name as well but that also didn't work.</p>
  
  <p>So how do you set the texture of a shader graph material with Universal Render Pipeline via code?</p>
  
  <p>The two planes ingame:</p>
  
  <p><a href="https://i.stack.imgur.com/sv9sT.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/sv9sT.png" alt="The two planes"></a></p>
  
  <p>Prebuilt plane's inspector:</p>
  
  <p><a href="https://i.stack.imgur.com/PIqCM.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/PIqCM.png" alt="The prebuilt plane&#39;s inspector"></a></p>
  
  <p>Shader Graph:</p>
  
  <p><a href="https://i.stack.imgur.com/RjrRn.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/RjrRn.png" alt="The shader graph"></a></p>
  
  <p>The script:</p>
  
  <pre><code>void Start()
  {
      GetComponent&lt;MeshRenderer&gt;().material.SetTexture("_MainTex", new TextureGenerator().GenerateNoiseTexture(256, 256));
  }
  </code></pre>