Search Unity

change terrain splatmap/alphamap

Discussion in 'Scripting' started by kiriri, Oct 24, 2013.

  1. kiriri

    kiriri

    Joined:
    Jan 14, 2011
    Posts:
    107
    Hi, I need to procedurally generate my terrains. In my case, depending on where the user clicks on a world map, different splat maps should be applied to the local terrain. How does one do this ?

    This code :

    Code (csharp):
    1.     TerrainData t = gameObject.GetComponent<Terrain>().terrainData;
    2.     t.splatPrototypes[0].texture = exampleTex;
    3.     t.RefreshPrototypes();
    ..does exactly nothing.

    So after some time to think, I got the idea to just change the Terrain material instead. However, since TerrainRenderer is an internal-sealed non Monobehaviour(eg it does not inherit from MeshRenderer and therefore cannot be gotten via .renderer) I can't see a way to get its' Material. Terrain.materialTemplate returns null, so that's not it either.

    Any help would be appreciated on this. I'd go great lengths to finally be able to set my splatmaps via code.

    [This is a duplicate post of http://answers.unity3d.com/questions/563595/get-terrain-material-set-splat-maps.html ]
     
    Last edited: Oct 26, 2013
  2. kiriri

    kiriri

    Joined:
    Jan 14, 2011
    Posts:
    107
    *bump*
    I'm bumping this thread because I really don't know what else to do, and I don't think anyone would read this while it's on page 4 :S

    Should I perhaps hand in a bug report due to t.RefreshPrototypes() not doing its' job? I mean, SplatPrototypes has "Prototypes" in its' name so in my opinion it should be included in the RefreshPrototypes() function.

    But I'm straying away from the original topic. I know there is a solution to this because there are plugins like Terrain Tile Editor that change the shader of the terrain and modify the splatmaps.