Search Unity

  1. The 2022.1 beta is now available for testing. To find out what's new, have a look at our 2022.1 beta blog post.
    Dismiss Notice
  2. Welcome to the Unity Forums! Please take the time to read our Code of Conduct here to familiarize yourself with the rules and how to post constructively.

How to use TerrainData.DirtyTextureRegion

Discussion in 'World Building' started by isaac-ashdown, Jul 20, 2020.

  1. isaac-ashdown

    isaac-ashdown

    Joined:
    Jan 30, 2019
    Posts:
    69
    Hello,

    I'm creating unity terrains at runtime. For the alpha/diffuse, I get the texture using TerrainData.GetAlphamapTexture, write some pixels (via GetRawTextureData), and call Texture2D.Apply().

    However, my alphamap is pretty high resolution, and calling Apply() is quite expensive. I see TerrainData.DirtyTextureRegion exists and should support both handling sub-regions of the texture and delayed syncing, but I can't work out how to use it with alphaMaps. In particular, what name should be passed in for textureName? If I pass in the Texture2D.name of the texture returned by TerrainData.GetAlphamapTexture, it reports 'ArgumentException: Unrecognized terrain texture name: "SplatAlpha 0"'. If I pass in TerrainData.AlphamapTextureName, then I nothing happens to my texture after calling SyncTexture. It all works fine if I just call Apply on the texture though.
     
unityunity