Changing MainTex Offset on material

I can’t seem to change the offset on my material of the texture
This is the two things I’ve tried.
Also it doesn’t work by changing it in the inspector either.

material.mainTextureOffset = new Vector2(Random.Range(0,1f),0);
material.SetTextureOffset("_MainTex", new Vector2(Random.Range(0,1f),0));

Using Unity 5.6.1 p4

Then it’s likely not implemented in the shader you’re using.

I have problems even with shaders properly set up in many cases.
Definitely have <tex_name>_ST declared and using TRANSFORM_TEX as well.
Used to work in 5.4.3.

Oh so this is something that can be added to the shade script?

@Shadowing This should clear things up: Handling Texture Tiling and Offset in a Unity3d Vertex and Fragment Shader using TRANSFORM_TEX macro

Thanks @npatch1
My large issue right now is I don’t know C++ or what ever shaders use.
Here is my shader script below
I couldn’t make those changes work.
Gives me fatal error with using TRANSFORM_TEX return value on o.textcoord

// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'

Shader "FORGE3D/Warp Jump" {
Properties {
    _TintColorA ("Tint Color A", Color) = (0.5,0.5,0.5,0.5)
    _TintColorB ("Tint Color B", Color) = (0.5,0.5,0.5,0.5)
    _Mult ("Color strength", float) = 1
    _MainTex ("Particle Texture", 2D) = "white" {}
    _InvFade ("Soft Particles Factor", Range(0.01,3.0)) = 1.0
}

Category {
    Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" }
    Blend One One
    AlphaTest Greater .01
    ColorMask RGB
    Cull Off Lighting Off ZWrite Off Fog { Mode Off }
  
    SubShader {
        Pass {
      
            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag
            #pragma multi_compile_particles

            #include "UnityCG.cginc"

            sampler2D _MainTex;
            float4 _TintColorA, _TintColorB;
          
            struct appdata_t {
                float4 vertex : POSITION;
                fixed4 color : COLOR;
                float2 texcoord : TEXCOORD0;
              
            };

            struct v2f {
                float4 vertex : SV_POSITION;
                fixed4 color : COLOR;
                float2 texcoord : TEXCOORD0;
                #ifdef SOFTPARTICLES_ON
                float4 projPos : TEXCOORD1;
                #endif

            };
          
            //float4 _MainTex_ST;
            uniform float4 _MainTex_ST;

            v2f vert (appdata_t v)
            {
                v2f o;
                o.vertex = UnityObjectToClipPos(v.vertex);
                #ifdef SOFTPARTICLES_ON
                o.projPos = ComputeScreenPos (o.vertex);
                COMPUTE_EYEDEPTH(o.projPos.z);
                #endif
                o.color = v.color;
                //o.texcoord = v.texcoord;
                o.textcoord = TRANSFORM_TEX(v.texcoord, _MainTex);
                return o;
            }

            sampler2D_float _CameraDepthTexture;
            float _InvFade, _Mult;
          
            float4 frag (v2f i) : SV_Target
            {
                #ifdef SOFTPARTICLES_ON
                float sceneZ = LinearEyeDepth (SAMPLE_DEPTH_TEXTURE_PROJ(_CameraDepthTexture, UNITY_PROJ_COORD(i.projPos)));
                float partZ = i.projPos.z;
                float fade = saturate (_InvFade * (sceneZ-partZ));
                i.color.a *= fade;
                #endif
              
                float4 final = tex2D(_MainTex, i.texcoord);
                final = lerp(_TintColorA * _TintColorA.a * _Mult, _TintColorB * _TintColorB.a * _Mult, final * _Mult) * final;

              

                return float4(i.color.a * final.xyz * i.color.xyz, 1);
            }
            ENDCG
        }
    }  
}
}

Ahh nevermind the guy who made the effect package I use told me what to edit to fix it.
Its all good now.

I had to change

float4 final = tex2D(_MainTex, i.texcoord);

with this below

float4 final = tex2D(_MainTex, TRANSFORM_TEX(i.texcoord, _MainTex));

Shaders are never written in C++. Here it’s a variant of HLSL , also called Cg.

Yeah, that’s because you’ve made a typo. o.textcoord should be o.texcoord.

PS: Your change works too but the previous version would have also worked if not for the typo.

Unity shaders are just HLSL now, not Cg. It was originally Cg, but if you try to use features that were unique to Cg it will fail. The code outside of the CGPROGRAM blocks (which are really HLSLPROGRAM blocks) is Unity’s own ShaderLab language which is a very simple markup language used to tell Unity how it should use the shader code when rendering. Because it was originally written to wrap around Cg there are some vestiges of that, like the use of CGPROGRAM / ENDCG and “fragment” shader vs “pixel” shader.

oh wow nice catch haha. I guess I rely on my editor to much. My editor doesn’t support that language so it didn’t catch that lol.
It works now. I don’t any difference though.

@bgolus indeed.

@Shadowing Do you mean no difference when you alter the Tiling/Offset variables in the Inspector?

I mean i see no difference from doing the changes in the link you gave.
Everything works now after the changes I made posted above.

Yes because there was a typo. But you’re doing the same thing so it doesn’t make a difference.