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
1
Question by sanderman0 · Aug 14, 2010 at 06:49 PM · terrainheightmapterraindata

Inserting heights in TerrainData

Hi.

I'm experimenting with procedural landscape generation and paging terraintiles. Every TerrainTile has a Unity Terrain and is being populated with heights. I am having some difficulties with building the TerrainData object for each terrain.

In this case my goal is a terrain tile of 1km square in size with a resolution of 129. My initial assumption was I could set the desired size and feed the TerrainData object with a 129x129 array of floats.

Naturally. It isn't that easy. For this purpose the SetHeights method is needed but it has no description so I haven't a clue how to use it.

Through some experimentation and studying the exceptions the mapsize seems set to 33, with no way to change it. And I have no idea what the xBase and yBase mean.

Am I looking at this from the wrong angle? It would be great if someone could explain this in more detail.

Comment
Add comment · Show 1
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 Tobias Reich · Oct 16, 2013 at 10:45 PM 0
Share

So is there no solution for this? I seem to have the exact same problem and no clue!

2 Replies

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

Answer by Eric5h5 · Aug 14, 2010 at 07:07 PM

My initial assumption was I could set the desired size and feed the TerrainData object with a 129x129 array of floats.

That is correct, and yes it's that easy.

myTerrain.terrainData.SetHeights(0, 0, myTerrainData);

Where "myTerrain" is a Terrain and "myTerrainData" is a float[,]. The terrain resolution is not fixed at 33; it's only 33 if you've specifically set it that way (which would result in a very low-res terrain). If the resolution is 129, then you use a 129x129 array of floats. The xBase and yBase are the x and y offset; if you're setting the entire terrain, then they would be 0. If you weren't setting the entire terrain, then the offsets would be non-zero depending on where you wanted to put the section of terrain data.

Comment
Add comment · Show 2 · 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 sanderman0 · Aug 15, 2010 at 08:49 AM 0
Share

Thanks but I still get exceptions when I try to feed it my 129x129 array. It seems the resolution is set to 33 by default when a TerrainData is constructed, but where do I change this? heightmapWidth and heightmapHeight are read-only. I've found a heightmapResolution property but this is not documented in the script reference. Is it safe to use?

This is the exception I am getting:

Exception: X or Y base out of bounds. Setting up to 129x129 while map size is 33x33 UnityEngine.TerrainData.SetHeights (Int32 xBase, Int32 yBase, System.Single[,] heights) [0x00000]

avatar image Eric5h5 · Aug 15, 2010 at 09:27 AM 0
Share

@Sanderman: since TerrainData.heightmapResolution isn't documented, it shouldn't be used in a webplayer because it can break in the future. Generally you'd create the TerrainData asset in the editor the usual way, then you can reference it in a script. (If you need to dynamically generate different terrain resolutions from script, that's not really feasible though.)

avatar image
0

Answer by Trond · Apr 06, 2019 at 09:23 PM

You need to set up the property called heightmapResolution. This is by default 33 (32+1), and needs to be a power of 2 + 1.

Comment
Add comment · 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

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

2 People are following this question.

avatar image avatar image

Related Questions

Spherical Terrain or screenshot to texture 0 Answers

generate terrain by script 0 Answers

"Terrain.activeTerrain" what does it do? 1 Answer

How to generate a complete terrain via Script 0 Answers

Unity imports heightmaps in kind of upside down order. 0 Answers


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