- Home /
Terrain Tile Seams and Terrain.SetNeighbor
Overview
Via a Unity Editor script, I am loading a GIS elevation GRID via a header txt file and binary float file. I am reading the large data set, choosing the nearest power of 2 and filling a corner with the real data. Then I break the large data set in to 513x513 terrain chunks and create the Terrains and gameObjects.
I am getting LOD seams between the TerrainChunks but only after starting the simulation, just after creating the tiles in the editor and before pressing play I can see that the terrain.setNeighbor() is working correctly. But pressing play and going into game mode changes that and the seams can be seen, after stoping the game simulation the terrain chunks continue to not respect the neightbors LOD.
Relevant Code
for( int y = 0; y < numberOfChuncks; y++ )
{ for( int x = 0; x < numberOfChuncks; x++ ) { Terrain left = null; Terrain top = null; Terrain right = null; Terrain bottom = null;
// Terrain Tile layout
// (x,y)
// (0,2)(1,2)(2,2)
// (0,1)(1,1)(2,1)
// (0,0)(1,0)(2,0)
//TOP
if( y == numberOfChuncks - 1 ) top = null;
else top = terrainObject[x,y+1].GetComponent();
//BOTTOM
if( y == 0 ) bottom = null;
else bottom = terrainObject[x,y-1].GetComponent();
//LEFT
if( x == 0 ) left = null;
else left = terrainObject[x-1,y].GetComponent();
//RIGHT
if( x == numberOfChuncks - 1 ) right = null;
else right = terrainObject[x+1,y].GetComponent();
//MAKE IT SO
terrainObject[x,y].GetComponent().SetNeighbors( left, top, right, bottom ); terrainObject[x,y].GetComponent().heightmapPixelError = 2; } }
Questions
Do I need to update Terrain.setNeighbors per frame? Is the fact that this is a Editor Scrip restricting the neighbors to only the editor window?
Thanks Chase
Answer by Bunny83 · Jul 13, 2012 at 12:23 AM
You certainly don't need to call it every frame, but i'm not sure if the neighbor information is stored in the terrain asset. You might need to call setNeighbors in Start()
edit
I just had a look into the Terrain script and, as i guessed, the neighbor-variables aren't serialized:
[NonSerialized]
private Terrain m_LeftNeighbor;
[NonSerialized]
private Terrain m_RightNeighbor;
[NonSerialized]
private Terrain m_BottomNeighbor;
[NonSerialized]
private Terrain m_TopNeighbor;
So you need to setup the neighbors at runtime. One way is to store the terrain list in a custom script along with the terrains and have it's Start method setting the neighbors.