Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

seamless terrain question

Discussion in 'Editor & General Support' started by alanis, Mar 21, 2009.

  1. alanis

    alanis

    Joined:
    Mar 4, 2009
    Posts:
    99
    ive been looking pretty much on unity documentation as well as here in the forums, but cant seem to find information or exaples on how to do seamless terrain or seamless world creation, ie: create several terrains and join them together as the player can walk thru the zones without even noticing when walking thru different zones.

    ive seen a few threads people asking the same question but dont see any clear way to do it, unless i ve missed it.

    what ive seen other users stating that it can be done thru a script called terrain.setneighbor () but can anyone set an example in noob terms on how this is done?

    for example to test arround on the demo island, if i create another terrain in this same demo project how do i or how can i enable the feature to page them together to create a seamless terrain or zones.

    I will appreciate it much.

    thanks for your time in advanced.
     
  2. Achim

    Achim

    Joined:
    Dec 19, 2007
    Posts:
    199
    very good question(s), i hope for good answers too.
     
  3. jonas-echterhoff

    jonas-echterhoff

    Unity Technologies

    Joined:
    Aug 18, 2005
    Posts:
    1,664
    1) Lay out the terrains to be located directly adjecent to each other (by editing the location in the transform components)

    2) Use the SetNeighbors function to tell Unity that the terrains are adjecent (so that Unity can adjust the LOD to be seamless across terrain borders). This has to be done for all terrains, so if you have two neighbouring terrains A, B, you need to call A.SetNeighbors(B, null, null, null) and B.SetNeighbors(null, null, A, null) for example.
     
  4. kfrench16

    kfrench16

    Joined:
    Mar 22, 2009
    Posts:
    73
    Brand new to unity. I just started playing with the demo yesterday (3/21).

    Positioning the terrains: are all of the terrains in the same scene or are they separate scenes?

    Where would you place the SetNeighbors functions for each terrain?

    Thanks
     
  5. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    The SetNeighbor function would be in the Start Function of a component thats aware of the terrain and its neighbors
     
  6. AngryAnt

    AngryAnt

    Keyboard Operator Moderator

    Joined:
    Oct 25, 2005
    Posts:
    3,045
    So you could have all the terrains in the same scene (probably preferable if you're new to unity) or in separate scenes which you stream in when needed (more code necessary).
     
  7. Achim

    Achim

    Joined:
    Dec 19, 2007
    Posts:
    199
    Hallo,

    i have two questions to set.Neighbors

    first: i tried this, but this doesnt work. How do i have to write it ?

    Code (csharp):
    1. var A: Transform;
    2. var B: Transform;
    3. function Start(){
    4.  
    5.     A.SetNeighbors(null,null,B,null);
    6.  
    7. }
    second: does the set.neighbors thing bring the seams of two terrains together when starting the player or what does it do ?
    because it is almost impossible to get seamless edges from hand or tiled heightmaps
     
  8. alanis

    alanis

    Joined:
    Mar 4, 2009
    Posts:
    99
    @Achim

    I am trying to figure this out myself,

    @unity dev team, or to whom it may concern.

    I just can believe Unity team does not have any documentation on this feature, unless i am completely blind and or missed it, a tutorial will be great for this topic.

    I mean, streaming or seamless terrains is a great one of kind feature, feature that pretty much does not exist on the majority of the other game angines,
    This should be a major sales pitch for unity.

    Look at the 3d platform tutorial is a great tutorial, awesome. it cover so many stuff that will get any noob to dive in to the game developing with unity so easy.


    In my opinion , I would love to see a tutorial on how to use this awesome feature, or any documentation if possible.

    Unless, it is assumed that any game dev with experience should know how to use this feature even if he or she just recently started using unity engine.


    I am trying to figue out why only there is a few threads regarding this topic with little to non concrete explanatios or guides. unless seamless terrains is not a usable feature or is not important for game devs.


    anyways, sorry if i got a little carried away, I guess i got frustrated trying to make this work with no success.

    feel free to post your input if any.

    thanks again in advanced.
     
  9. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    The documentation can be found in your terrain documentation, more specifically here


    Thats all that is there and thats required to know about it.
    In the editor you would create several terrains, align them correctly and likely have a management script with a 2D array where you assign the different terrain blocks according their positioning to be able to set the neighbors simply (a more flexible but less easy solution is building this array dynamically basing on the terrains position)
    This script optimally is running in editor mode as well to have smooth terrain switches there as well.

    The feature is simply a "link terrain blocks together to work smoothly like a larger terrain" but within the editor etc you still work on distinct terrain blocks.


    Perhaps you expect that there are more things like streamed terrains etc, but this is not the case.
    You can do further things like loading in the blocks dynamically at runtime and set the neighbors dynamically, thats what you likely will do for a really large world.
    But that is not related to this feature as that is a common game object / resource / asset handling topic, not related to terrains in any way
     
  10. Achim

    Achim

    Joined:
    Dec 19, 2007
    Posts:
    199
    @dreamora


    i know where to find in the reference but i dont know how to write the correct script. can you give a working example ?
     
  11. alanis

    alanis

    Joined:
    Mar 4, 2009
    Posts:
    99

    Exactly, i am trying to learn to loading blocks and setneigbors dynamicaly at runtime to build a large world,
    if you have any input on it, I will appreciate it very much.
    Now, will this feature available in the indie license?
    thanks in advanced
     
  12. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    this feature always has been present in the indie license.

    This feature is used pretty project specific commonly, but here a basic script you can assign to a general management object in your scene and assign 4 aligned terrain blocks to it.

    This is written out of head but should work just fine

    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4.  
    5. public class TerrainTiler : MonoBehaviour {
    6.  
    7.     public Terrain[] terrains;
    8.     /*  Expects an array with 4 entries
    9.     *   Layed out like:
    10.     *   0 1
    11.     *   2 3
    12.     */
    13.     // Use this for initialization
    14.     void Start () {
    15.         if( terrains.Length != 4 )
    16.             throw new System.Exception("Incorrect number of terrains");
    17.                
    18.         terrains[0].SetNeighbors( null, null, terrains[1], terrains[2] );
    19.         terrains[1].SetNeighbors( terrains[0], null, null, terrains[3] );
    20.         terrains[2].SetNeighbors( null, terrains[0], terrains[3], null );
    21.         terrains[3].SetNeighbors( terrains[2], terrains[1], null, null );
    22.     }
    23.    
    24.     // Update is called once per frame
    25.     void Update () {
    26.    
    27.     }
    28. }
     
  13. alanis

    alanis

    Joined:
    Mar 4, 2009
    Posts:
    99


    Thank dreamora,
    ok, I think i am starting to get the hang of setneighbors to join terrains,

    1 question:
    In the initialization part, does this mean when scene is loading all 4 terrains will have to load at the same time in the scene, right?

    Or will they be loading dynamicaly each terrain block on demand, what i mean on demand is when the ingame character walks thru the terrains blocks and terrains will load individually and as the character steps in next block the old block will be destroyed?

    the reason that i ask this is for example:
    I guess i can make a very large world and keep just adding blocks of terrain in the scene and use the setneigbors to join them, but there will be a limit of terraisn a scene can handle right?, since there will be so much that memory can handle if all terrains are loaded at once,

    so if load terrains dynamicaly on demand as character or player moves arround and only have the present terrain in which the character is on active, and destroy the previous ones and if the further he walks into another terrain chunk the old one will get destroyed to release memory.


    Or am i confused or confusing you, lol

    anyways, thank you for your input, if you have any comments or advices will be greately appreciated.

    regards
     
  14. Achim

    Achim

    Joined:
    Dec 19, 2007
    Posts:
    199
    @dreamora
    Thanks a lot for this script/example !
     
  15. ykk

    ykk

    Joined:
    Dec 8, 2009
    Posts:
    51
    Can you upload a simple assets for this? How to set terrain on different position? Because all terrain I import on same position.
     
  16. alexnode

    alexnode

    Joined:
    Jan 27, 2010
    Posts:
    63
    move them from the inspector ...
     
  17. Kourosh

    Kourosh

    Joined:
    Jul 18, 2010
    Posts:
    15
    Just one thing, my script creates tiles of flat terrains and setneighbors them correctly now I wanna know how do I apply my raw terrain heightmap in a way that each terrain gets its share of the heightmap and not the entire map. Yes I'm trying on this TOD (Terrain On Demand) but there isn't just one example covering top to toe.
    Thanks for your help:)
     
  18. decalibrated

    decalibrated

    Joined:
    Apr 10, 2011
    Posts:
    8
    I would like to add that if you put this in the Awake function you get weird shadows around the terrain seams, and they stick even when the script gets turned off.

    If you are having this problem, simply make sure the SetNeighbors() is in the Start function as dreamora has stated. I was really freaking out for a second.

    And to clarify a point, I did notice that my terrain borders lined up perfectly with SetNeighbors on, and had noticeable gaps without it, probable the same gaps that created the shadow seams.

    Good luck to all
     
  19. RoyS

    RoyS

    Joined:
    Jan 12, 2009
    Posts:
    664
    Sleglik has a Terrain Kit in "Assets and Asset Store" that can do this and other features. http://forum.unity3d.com/threads/102649-Simple-terrain-mapper

    - Sleglik in one of his posts.
     
  20. sh0v0r

    sh0v0r

    Joined:
    Nov 29, 2010
    Posts:
    295
    Hi I have been building large terrains, 6.147 x 6.147 klms - 3x3, 2049 heightfields at 1mtr scale.

    I used L3DT(google it) to create my terrain which does nice erosion passes and then it also can output the heightfield so it tiles or subdivide a large heightfield into smaller tiles.

    You then create a new terrain for each tile and manually import each heightfield.

    You will then need to get Stitchscape which will fix any miss alignment with edge pixel values being different.

    Set neighbours only ensures the dynamic terrain LOD or tesselation matches with its neighbour you will still need to ensure the edges of each heightfield have the same height values.

    The only issue I have had is lightmapping each individual terrain so that each terrain affects the other terrain when bouncing light off each other or casting shadows it doesnt seem to work. You will want to lightmap them as this is much faster than Vertex lighting.



    Unity limits Terrain heightfields to 4096x4096.
     
    Last edited: Sep 29, 2011
    Valthaer likes this.
unityunity