mesh to unity terrain

 

By using this script, you can easily convert (.obj or .fbx) mesh to Unity Terrain.

ORIGINAL POST

Object2Terrain

 

1. First, you need to download Object2Terrain.cs and put in inside Unity Editor folder.

 

2. Then import any mesh to Unity which you want to convert, and put it inside the Hierarchy (Scene).

3. With that mesh selected in the Hierarchy (Scene), at the top toolbar select Terrain > Object To Terrain.

4. You will see some settings pop up. Leave them at default and press Create Terrain.

If you want to have a higher poly terrain, or just want to paint more detail on the terrain, increase the Resolution value (it will increase the tris count of the terrain). Or lower it if you want to decrease the detail.

5. DONE! Here you can see that a new Terrain was created. It’s overlapping my original mesh, this way I can see how accurate my Unity Terrain looks.

Let’s hide original mesh and leave the Terrain to see it better.

You can edit the terrain if you want. Select Terrain and do whatever you can with Unity Terrain Editor (create hills, paint texture, grass, trees, etc.).

 

MY UNITY PREFAB IS GONE – FIX

If you create the Terrain Prefab, it won’t work after you close Unity and run it again! That’s because Unity Terrain should have Terrain Data file, which is NOT created using Object2Terrain converter:

Originally when you create Unity Terrain, Terrain Data file is created too:

You can find it inside Assets folder.

 

To fix this, you need to:

1. Select the Terrain which was created using the converter. Go to Terrain Settings.

scroll down and press Export Raw… (to export Height Map).

Depending or your device, select Windows or Mac and Export using default settings.

2. Hide the Terrain, so it won’t distract us.

3. Create a new Terrain (inside Hierarchy press on Create > 3D Object > Terrain). With our new Terrain (1) selected,  go to Terrain Settings.  Scroll down, you will see Resolution tab.

We need to copy:

  • Terrain Width
  • Terrain Lenght
  • Terrain Height
  • Heightmap Resolution

from our hidden Terrain and paste these exact settings here inside our newly created Terrain (1).

Now Terrain (1) settings should look like this (it depends on your converted Terrain settings):

4. With Terrain (1) selected, inside Terrain Settings press on Import Raw… (to import Height Map we exported before).

Select that Height Map and import it. Depending or your device, select Windows or Mac and Import using Default settings.

THAT’S IT! Now we have Terrain (1) which looks like converted Terrain.

It has Terrain Data!

that means if I drag and drop Terrain (1) to the Project tab, it will create a prefab. And now I can save it, quit Unity, launch it again, and I will have fully working Terrian (1) prefab 🙂

 

Feel free to ask me some questions!

 

If you want to see more stuff I’m working on, follow me on Twitter: @lmhpoly

You can support me by Subscribing to my YouTube channel, it helps me to create more video content for you guys 😉 Video tutorials, Time-lapse videos and more!

You can also follow me on Facebook, Instagram and Google+

Pin It on Pinterest