- Home /
Unity Batch Terrain Creation Script?
Hi all,
I'm new to Unity, but not to programming. I'm just browsing over the API, and can't find the necessary calls to do what I want.
Basically, I want to create a new TerrainData object, set heights, and then set texture, and lightmap (all of which I'm ok on). Here's the thing, I want to do this without creating a terrain object, and want to save the TerrainData object to the Project folder.
Basically, I'm gonna plough through a batch of terrain tiles, and create a TerrainData object for each, then save all these somewhere in the Project folder (preferably the Resources folder).
Any ideas anyone?
Answer by qJake · Aug 08, 2010 at 11:12 AM
Just write an editor script that does this:
Create a game object.
Add a Terrain component to it.
Set stuff with the terrainData property.
"Save" the asset by actually creating a new asset using AssetDatabase.CreateAsset. I don't know what file extension you need to use (it matters!), so just create a Terrain using the editor, and then browse to where it is in your Assets folder on your computer, and see what file extension it is (it might be ".asset" or ".terrain" if I had to guess).
Hi, I may be missing something here, but I need to get the TerrainData assets into the Resources folder of that particular build. AssetDatabase.CreateAsset doesn't seem to do this, even with path "Assets/Resources/data.asset"..
TerrainData isn't an asset, it's a data structure that's tied to a Terrain object that provides the heightmap and related information. You can't have a "TerrainData" asset.
Yes you can. Indeed, you can make two Terrain objects with the same TerraidData (not sure why you would, but you can).
Uh... I'm pretty sure Unity won't let you create a TerrainData asset via the Editor (I'm talking about a physical asset here, that shows up in the Asset list), but if you used CreateAsset(), it might be possible, I haven't checked. I think it's doubtful, though.