Author Topic: How to change Tiling / Offset of all generated Textures by script?  (Read 11345 times)

Hello everyone,
i'm using B2M3 for a material that i would like to scale at runtime. Within the Unity Editor, whenever i change the tiling of the upmost "Base (RGB)" texture, the values of the generated Normalmap and Heightmap are automatically updated to the new value. Now i'm trying to change the Tiling at runtime, but i've only succeeded for the Diffuse texture by setting myGeneratedMaterial.mainTextureScale. However this doesn't affect my Normalmap and Heightmap. Is there a way to change them, too?

Any suggestions are highly appreciated!
cheers, andy

Hi ponx,

If you want to change it at runtime, you'll have to set it for all the textures you want to transform.
You can use "SetTextureOffset" and "SetTextureScale" with the textures identifiers (depending on your shader).
Here is a sample of code:

Code: [Select]
GetComponent<Renderer>().material.SetTextureOffset("_MainTex", new Vector2(myOffsetX, myOffsetY));
GetComponent<Renderer>().material.SetTextureOffset("_BumpMap", new Vector2(myOffsetX, myOffsetY));
GetComponent<Renderer>().material.SetTextureScale("_MainTex", new Vector2(myScaleX, myScaleY));
GetComponent<Renderer>().material.SetTextureScale("_BumpMap", new Vector2(myScaleX, myScaleY));
Lead technical artist

Hi Gaetan,
thanks alot for your quick reply! it works!  ;D
I also needed the to set the _ParallaxMap, which i only found by a google search based on the other identifiers you mentioned. Is there a way to obtain a list of all identifier-strings using the scripting API? Or can i rest assured that they won't change in a future update?

best, ponx
Last Edit: November 04, 2014, 08:35:28 pm

Hi ponx,
The identifiers are not based on the Substance you use but on the shader (you set in your Unity material).

If you still use the same shader (don't modify it) in a future version, the identifiers will not change.
But if you switch to another one (for example if you choose to use PBR in Unity 5), the identifiers can be different.
You can eventually check at the beginning of your script if the shader name is the same (using "GetComponent<Renderer>().material.shader" for example) to be sure everything is ok, but it's not requiered.

Lead technical artist