Search Unity

Resolved Spriterenderer and _MainTex

Discussion in 'Shader Graph' started by Zoulz, Mar 22, 2021.

  1. Zoulz

    Zoulz

    Joined:
    Mar 14, 2014
    Posts:
    13
    Ahoj! i've made a sprite shader in shader graph with a exposed texture2d property called _MainTex. I then created a material with this shader and applied it to a object's sprite renderer. But the editor keeps complaining that the material has no _MainTex property exposed (though it clearly does). And it doesn't seem to use the texture from where the sprite comes from. It uses the texture from the material. I could make individual materials for all my sprites and hardcode the texture in each material, but that seems a bit wasteful. Any idea why spriterenderer doesn't seem to find the property in the shader?
     
  2. Lo-renzo

    Lo-renzo

    Joined:
    Apr 8, 2018
    Posts:
    1,514
    It'll still complain if your _MainTex's Sample Texture2D node isn't hooked into the final output somehow. It's probably that there's another issue with your graph. You should post what you have so we can see what's wrong.
     
  3. Zoulz

    Zoulz

    Joined:
    Mar 14, 2014
    Posts:
    13
    It's a very simple graph right now. Here it is:
     
    MJunior1989 likes this.
  4. Lo-renzo

    Lo-renzo

    Joined:
    Apr 8, 2018
    Posts:
    1,514
    On the blackboard, unfurl the _MainTex property. Is the Reference field _MainTex? The name of the property can be whatever ("My Stupendous Main Tex"), but the Reference field must be _MainTex.
     
    Zoulz likes this.
  5. Zoulz

    Zoulz

    Joined:
    Mar 14, 2014
    Posts:
    13
    Ahhh yes, it was named something generic. I changed it to _MainTex and now it seems to be working! thank you very much :)
     
  6. MJunior1989

    MJunior1989

    Joined:
    Jul 31, 2018
    Posts:
    2
    Thanks bro for me it worked perfectly!