- Home /
MaterialPropertyBlock Main Texture Offset?
I've gotten into the habit of using MaterialPropertyBlocks to tweak shader properties at runtime, as to avoid creating new material instances for simple things.
The question I have, though, is how can I do this to tweak the material's main texture offset, so I can use a spritesheet of icons and not end up with a bunch of instanced materials (as that would cause the icons not to batch).
Answer by il88 · May 17, 2016 at 12:57 PM
I've found that you can modify texture transforms (offset and tiling) by setting _STs (uniform float4 _MainTexture_ST for example) like any other Vector4:
propertyBlock.SetVector("_MainTex_ST", new Vector4(0.5f, 0.5f, 0.25f, 0.25f));
The order of the values to pass to SetVector is scale.x, scale.y, offset.x, offset.y
, e.g. propertyBlock.SetVector("_$$anonymous$$ainTex_ST", new Vector4(scale.x, scale.y, offset.x, offset.y));
Not for a $$anonymous$$aterialPropertyBlock it isn't. $$anonymous$$aterialPropertyBlocks use strings to reference a shader value. https://docs.unity3d.com/ScriptReference/$$anonymous$$aterialPropertyBlock.html
I mean that is the order of the values for the vector.
im doing this and is not working to me , I'm using standard shader , whats wrong with what I'm doing I cant understand but I don't see the offset to be changed so far :S
If you're using URP, use "_BaseMap_ST" rather than "_MainTex_ST".
Your answer
![](https://koobas.hobune.stream/wayback/20220613160234im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
A node in a childnode? 1 Answer
Camera target 1 Answer
How to make an ingame weapon/ammo shop 0 Answers
Change the value of a Key in animation (via code) 0 Answers
Collision Detection in Capsule Collider 0 Answers