Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
2
Question by uray · Oct 25, 2011 at 08:44 AM · c#terrainterraindataprocedural-terrain

Creating TerrainData.Asset programatically

How do I create Terrain from script, I know about Terrain.CreateTerrainGameObject(), but this function accept TerrainData as an argument, and then by this forum topic the TerrainData instance must already be in Project view.

My question is how do I create that TerrainData instance from my script (without using Unity default Terrain tools). I'am planning to create custom heightmap importer for my terrain.

Comment
Add comment · Show 4
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image syclamoth · Oct 25, 2011 at 08:54 AM 0
Share

I'm not sure about this one (at all), but is there anything stopping you from calling 'new TerrainData()' and then assigning all the values to it at runtime? Or even, making a 'blank' default-settings TerrainData in your assets, instantiating that, and then doing your work using SetHeights() etc.?

avatar image syclamoth · Oct 25, 2011 at 08:55 AM 0
Share

Just read that forum topic- I can't really think of any reason why you can't just use that solution!

avatar image uray · Oct 25, 2011 at 09:07 AM 0
Share

I can't use that solution because it need to create terrain the normal way, which involved user clicking Terrain menu then create terrain, then delete the terrain and re-use its generated TerrainData.asset in Asset Folder by script, what I need to do is to create TerrainData.asset file from script, I need to create that file from script because I need to create multiple TerrainData for multiple terrain.

avatar image syclamoth · Oct 25, 2011 at 10:25 AM 0
Share

Yes, but once you've created one TerrainData, you can duplicate it, and then modify the duplicate, can't you?

1 Reply

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by jonas-echterhoff · Oct 25, 2011 at 02:35 PM

Try this:

     TerrainData terrainData = new TerrainData ();
     const int size = 513;
     terrainData.heightmapResolution = size;
     terrainData.size = new Vector3 (2000, 600, 2000);
     
     terrainData.heightmapResolution = 512;
     terrainData.baseMapResolution = 1024;
     terrainData.SetDetailResolution(1024, terrainData.detailResolutionPerPatch);

     AssetDatabase.CreateAsset(terrainData, "Assets/New Terrain.asset");
Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image memBrain · Sep 27, 2013 at 06:19 PM 0
Share

I am following your example, but it generates a whole slew of CS1519 Unexpected Symbol errors. What's going wrong here?

 using UnityEngine;
 using System.Collections;
 using System.Runtime.InteropServices;
 
 public class Game$$anonymous$$anager : $$anonymous$$onoBehaviour {
     ArrayList< GameObject > gameObjects = new ArrayList<GameObject>();
     
     TerrainData _terrainData = new TerrainData ();
     const int size = 513;
     
     
     _terrainData.heightmapResolution = size;
     _terrainData.size = new Vector3 ( 2000, 600, 2000 );
     
     _terrainData.base$$anonymous$$apResolution = 512;
     _terrainData.SetDetailResolution ( 1024, _terrainData.detailResolutionPerPatch );
     
     AssetDatabase.CreateAsset ( _terrainData, "Assets/New Terrain.asset" );
 }

I suppose I should add that the problem starts after the const declaration line. _terrainData is not recognized by auto complete. I've also pasted your code in place of $$anonymous$$e and get the same result. Each of the lines with _terrainData is highlighted red.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Distribute terrain in zones 3 Answers

copy smaller size terrain's data, and seet the heights on bigger Terrain at click position 0 Answers

How to generate multiple Terrain objects with different TerrainData and Splat Texture via C# script? 1 Answer

Problem with blending two terrains together on an edge. 1 Answer

How can I use feature recognition on terrain? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges