• 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 /
This question was closed Sep 28, 2015 at 07:24 PM by DeadKenny for the following reason:

The question is answered, right answer was accepted

avatar image
Question by DeadKenny · Sep 28, 2015 at 10:54 AM · terrainproceduralintterraindatadetail

Terrain set detail layer problem.

Ok, so I have this terrain that cuts itself up and then places stuff on. This code I have places details on the terrain using the Terrain scripts detail prototypes. However it only places the first detail in the list. I cannot get it to place anything other than the first. The last integer at the end of GetDetailLayer is supposed to do it but, nothing shows up if I change it to above 1. Setting it to 1 still only shows the first detail. I'm very confused please help. It should be working, I don't get it.

    void PlaceDetail(Terrain t, Vector3 pos, float radius)
     {
 
         int TerrainDetailMapSize = t.terrainData.detailResolution;        
         float pixelSize = TerrainDetailMapSize / t.terrainData.size.x;        
         Vector3 TexturePoint3D = pos - t.transform.position;
         TexturePoint3D = TexturePoint3D * pixelSize;    
         float[] xymaxmin = new float[4];
         xymaxmin[0] = TexturePoint3D.z + radius;
         xymaxmin[1] = TexturePoint3D.z - radius;
         xymaxmin[2] = TexturePoint3D.x + radius;
         xymaxmin[3] = TexturePoint3D.x - radius;
         int[,] map = t.terrainData.GetDetailLayer(0,0, t.terrainData.detailWidth, t.terrainData.detailHeight, 0);
         for (int y = 0; y < t.terrainData.detailHeight; y++) {
             if(xymaxmin[2] > y && xymaxmin[3] < y)
             {
                 for (int x = 0; x < t.terrainData.detailWidth; x++) {                
                     if(xymaxmin[0] > x && xymaxmin[1] < x)
                         map[x,y] = 1;
                 }
             }
         }
         t.terrainData.SetDetailLayer(0,0,0,map);
         t.Flush();
     




Comment

People who like this

0 Show 2
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 getyour411 · Sep 28, 2015 at 03:25 PM 0
Share

I think...

line 13 means "get all stuff on detailLayer 0" (that final 0 = detailLayer); if you wanted additional details you need 1,2,3...etc.

The same for SetDetailLayer, the 3rd "0" in (0,0,0...) is the Layer, if you want more details on additional layers, you need 0,0,1 0,0,2 etc.

avatar image DeadKenny getyour411 · Sep 28, 2015 at 07:23 PM 0
Share

Ah thanks, I got it working. Thanks a lot.

0 Replies

  • Sort: 

Update about the future of Unity Answers

Unity Answers content will be migrated to a new Community platform and we are aiming to launch a public beta later in June. Please note, we are aiming to set Unity Answers to read-only mode on the 31st of May in order to prepare for the final data migration.

For more information, please read our full announcement.

Follow this Question

Answers Answers and Comments

29 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Paint Terrain Texture From Vector3 List 0 Answers

Painting foliage through a script - what's wrong here? 0 Answers

Procedural terrain bigger than I set it, heightmap slightly off 0 Answers

How to make multiple terrains match together? 2 Answers

What the hell? Cannot convert float to int PROBLEM. 2 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