I am generating terrain date using a script. This works very well but when I try to save it as an asset, it fails.
can some one advise. I’m saving to a folder in the assets folder named ‘world’.
TerrainData terrainData = new TerrainData();
terrainData.heightmapResolution = m_heightMapRes;
terrainData.alphamapResolution = m_controlMapRes;
terrainData.SetHeights(0, 0, htmap);
terrainData.size = new Vector3(m_terrainWidth, m_terrainHeight, m_terrainLength);
GameObject NewTerrain = Terrain.CreateTerrainGameObject(terrainData);
AssetDatabase.CreateAsset (terrainData,"Assets/world/terrain.asset" );
I tried just dragging and dropping the terrain after the script created it, but it doesn’t save the terrain data. Although when left in the scene, it displays the terrain just fine
this would be a really nice feature to have in unity.
some other guy did want to same thing 4 years ago… link, but no-one answered him.
i did try the same and get the following error.
UnityException: Creating asset at path D:/TerrainProject/Assets/SavedTerrain.asset failed.
i also did try to open an “New Terrain.asset” with hexeditor and notepad to see how it’s build up, but well… that doesn’t make it easier.
perhaps the unity folks would clear some things up why we can load a terrainData.asset file with the command “CreateTerrainGameObject(TerrainData assignTerrain”, but why isn’t there some command to save the terrain(data) to a file.
i would like to have an employee of unity to contact me about this. (this is a really importand thing for me and my company, but i don’t know who i have to contact about this.)
Well actually I think I have discovered a way around this. I will be producing a editor extension for this purpose of which I will be sharing with the community
well, i can do it to. but it’s easier to have it this way.
i can already save every terrain data to disk (txt files and such), and load it later on.
it’s a heavy function (and big). it works like a charm, but it sucks memory. so saving and loading to a TerrainData.asset file would be much nicer!
Yeah I started with a huge function to do it but in my experience after a while my unity crashes through lack of memory. This other way im doing is quicker and very low memory consumption. just perfecting it
i am really curious now
can you share with me how you do it?
when you are going to share it with the community, are you asking some payment for that? or are you sharing much needed (for me at least) knowledge for free? ^^
haha, you will see. it will be free as well its one of those things that is needed
Valrik, have you finished your terrain extension? I’m interested on it.
Can’t you just create an empty terrain… Run AssetDatabase.CopyAsset, instantiate the new asset, change the terrain data in code… and the changes should remain after you quit.
I’ve got sliced terrain. Have to store those sliced terraindata