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.

  • \$\begingroup\$ 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? \$\endgroup\$
    – DMGregory
    Apr 6, 2019 at 16:41
  • \$\begingroup\$ Stupid mistake because for some reason you don't set the normal map with "NormalMap" but "_BumpMap". \$\endgroup\$ Apr 6, 2019 at 18:54

1 Answer 1


Nevermind, the fact is you have to apply with a different name:

material.SetTexture("_BumpMap", normalMap);
material.SetTexture("_ParallaxMap", heightMap);

Why, would you ask? No sé, gringo. Anyway, I could have the full list of properties by switching the inspector to debug mode.

  • \$\begingroup\$ Glad you were able to solve your problem - don't forget to mark it as accepted. \$\endgroup\$
    – Pikalek
    May 7, 2019 at 15:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .