Search code examples
c#unity-game-engineterrain

splatmap textures not applying in build in unity


im procedurally creating my heightmaps and declaring my terrain in the scripts

in the unity editor, my splatmaps work perfectly, however when i build my terrain is just plain black.

is there a setting that i may have missed when building that is required to make the splats work ?.

editor http://answers.unity3d.com/storage/temp/31838-untitle2d.png

build http://answers.unity3d.com/storage/temp/31839-untitled.png

i load them in using code with

SplatPrototype[] terrainTexture = new SplatPrototype[4]; 
        terrainTexture[0] = new SplatPrototype(); 
        terrainTexture[0].texture = (Texture2D)Resources.Load("stone");
        terrainTexture[1] = new SplatPrototype(); 
        terrainTexture[1].texture = (Texture2D)Resources.Load("sand");
        terrainTexture[2] = new SplatPrototype(); 
        terrainTexture[2].texture = (Texture2D)Resources.Load("grass");
        terrainTexture[3] = new SplatPrototype(); 
        terrainTexture[3].texture = (Texture2D)Resources.Load("snow");

edit i attempted adding the textures to the code as variables draged in rather than using resource.load, also didnt work

edit i found a work around which makes it work, but its unfortunate that i coudnt find a proper solution. can anyone see something that could be the cause of the issue

http:// answers.unity3d.com/questions/171150/terrain-basemap-texture-through-code.html


Solution

  • You need to include an extra shader in your build. Go to edit -> project settings -> graphics. In the inspector increase the size. In the new slot select Nature/Terrain/Diffuse.

    The reason you need to do this is that Unity will search for any assets that are referenced in the scene to decide what to include in the build and what to leave out. Since your terrain is built procedurally there is no terrain object and no terrain material present, and the required shader is not included. By following the above steps you basically tell Unity to include it anyway because you know you are going to need it.