Search Unity

Nonadjacent Terrain Neighbors

Discussion in 'World Building' started by MitchellLawrenceOHair, Sep 3, 2020.

  1. MitchellLawrenceOHair

    MitchellLawrenceOHair

    Joined:
    Jan 7, 2018
    Posts:
    2
    EDIT: I have thought of a better way to ask my question:

    If I have terrains A, B, and C, where B is the right neighbor of A, and C is the right neighbor of B. Is it possible to have A be the right neighbor of C? (thus forming a loop of terrain neighbors.)

    I'm aware of the existence of Terrain.SetNeighbors, but I don't think it will help me because I need the neighbors to be defined before running the game so I can sculpt the terrain seamlessly.

    I'm trying to get my world to wrap around on itself and I have already written code to load/unload and move terrains to achieve that, however there will be height differences where C wraps around to A. (unless I have flat edges)

    =======================================================================
    Original question below
    =======================================================================

    I have a grid of neighboring terrain objects where each terrain object is in its own scene. When the scenes are all loaded I can use a height brush to get seamless elevation across the neighboring terrains as expected.

    What I would like to do is to set the neighbors of the edges of my grid to the terrain objects on the opposite edges of the grid. I'm going for a wrap around effect so I effectively have no world boundaries, but still have a finite space. (I already have a system for loading and unloading the terrains in the proper locations).

    Any help on where to start would be appreciated. If I have some egregious misunderstanding about how terrain neighbors work (which I suspect I might) please let me know. Thanks.
     
    Last edited: Sep 4, 2020
  2. MitchellLawrenceOHair

    MitchellLawrenceOHair

    Joined:
    Jan 7, 2018
    Posts:
    2
    So it turns out this is easy to do, but the end result leaves sculpting very inconvenient. Using [ExecuteInEditMode] one can use Terrain.SetNeighbors to assign a nonadjacent terrain as a neighbor of another terrain before the game is running, and even have terrain neighbor loops. (This can even be done across different scenes using GameObject.Find).

    The annoying thing though is that the developer needs to manually move the terrain to be adjacent to its neighbor sculpt along that edge, then move the terrain back to its original position. The heights along the edges will match up despite the terrains no longer being adjacent.

    If I sculpt carefully and take the time to do it, this will work for my small grid of terrains. However this solution would be unacceptably tedious and time consuming for larger game worlds.
     
  3. neoshaman

    neoshaman

    Joined:
    Feb 11, 2011
    Posts:
    6,493
    Write an editor script to handle it
     
  4. wyattt_

    wyattt_

    Unity Technologies

    Joined:
    May 9, 2018
    Posts:
    424
    Definitely make a custom script for this. Depending on your Unity version, on all of your terrains in the settings tab you can disable "Autoconnect". Then run your script to set up the neighbors however you want. If you make this script, you shouldn't have to move any terrains in order to paint. As long as that right neighbor is assigned, textures should be gathered and scattered appropriately.