# Unity: Change the type of a Texture2D to “Normal map” through script

I am making procedural terrains through c# script, and while I achieve to produce a texture, a heightmap and a normalmap to Texture2D, it seems they are not being applied correctly to the material.

• the texture (albedo) is applied
• the noise map is applied (but as a "default" texture, I think?)
• the heightmap is not even selected

The trick I currently use is to also save the Texture2D to files. After generation I manually affect the file normalMap and it goes fine. But you'll understand this is not satisfactory, I want the script to set the normal map correctly.

I suspect this is because the file's texture type is force to normal map. But I cannot see how I can change the type of an in-memory Texture2D through code.

Researches gave nothing fitting my concerns, any help will be appreciated. Thanks:)

[EDIT] I tricked by passing a pre-made normal map as parameter, to use instead of the one I generate. Guess what? It works instantly.

• There's not really such a thing as a normal map type at runtime. That setting in Unity just helps the editor select appropriate encoding/compression when packaging assets for each platform. You should be able to get the same results by generating your normal map directly in your desired format. Can you show us the code you're currently using to create and assign your normal map? – DMGregory Apr 6 '19 at 16:41
• Stupid mistake because for some reason you don't set the normal map with "NormalMap" but "_BumpMap". – Nicolas Cailloux Apr 6 '19 at 18:54

material.SetTexture("_BumpMap", normalMap);