Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Question How to get a terrain elevation map and transfer it to Render Texture

Discussion in 'Scripting' started by qwerh337, Jan 2, 2023.

  1. qwerh337

    qwerh337

    Joined:
    Oct 18, 2018
    Posts:
    7
    Hello, I'm asking for help.
    I'm trying to get a terrain elevation map and pass it to RenderTexture, but nothing comes out. I get the elevation map using "Terrain Data .heightmap Texture" in the help it says that it returns "public RenderTexture", but the variable itself is not involved in the script.
    Code (CSharp):
    1. public Terrain terrain;
    2.     public RenderTexture renderTexture;
    3.  
    4.     private void Start() {
    5.         renderTexture = terrain.terrainData.heightmapTexture;
    6.     }
    What am I doing wrong?
     
    Last edited: Jan 3, 2023
  2. qwerh337

    qwerh337

    Joined:
    Oct 18, 2018
    Posts:
    7
    What does no one know?
     
  3. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,954
    I've never used .heightmapTexture, not even sure what it might get you based on the documentation.

    You can use .GetHeights() on the TerrainData to get the heightfield data.

    After that I suppose you could produce a texture from those heights.
     
  4. chemicalcrux

    chemicalcrux

    Joined:
    Mar 16, 2017
    Posts:
    717
    Nitpicky vocabulary:
    heightmapTexture
    is a property of
    TerrainData
    . It is public, so anyone can access it. It returns a value of type
    RenderTexture
    !

    Anyway, I'm not really clear what the issue is here -- you're grabbing the render texture and storing it in a private variable, but you aren't doing anything with it!

    I'm guessing you want to use this render texture to draw a map. Are you having trouble getting it to draw correctly? What have you tried to do?
     
  5. qwerh337

    qwerh337

    Joined:
    Oct 18, 2018
    Posts:
    7
    I'm trying to get the texture of the elevation (at the beginning of the scene). The help says that
    terraindada.heightmapTexture
    returns the texture of the height map. I tried to get this texture, and since the same help says that heightmapTexture is a
    public RenderTexture,
    I tried to assign it to it in the script.
     
  6. chemicalcrux

    chemicalcrux

    Joined:
    Mar 16, 2017
    Posts:
    717
    That all sounds reasonable to me. What is going wrong?
     
  7. qwerh337

    qwerh337

    Joined:
    Oct 18, 2018
    Posts:
    7
    Nothing happens (just a black color in the texture), and in the ide Rider shows that
    terrainData
    does not return anything, the
    RenderTexture
    variable is empty. So I'm trying to figure out why.