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 /
This question was closed Oct 10, 2015 at 04:24 PM by getyour411 for the following reason:

Problem is not reproducible or outdated

avatar image
0
Question by Dunlain · Mar 03, 2013 at 01:52 PM · terrainrandomtree

Any Reason this would make Unity Freeze up?

     private void PlantTrees(){
         int treeTypes = terrain.terrainData.treePrototypes.Length - 1;
         int maxZ = (int) terrain.terrainData.size.z,
             maxX = (int) terrain.terrainData.size.x;
         
         for(int z = 1; z < maxZ; z++){
             for(int x = 1; x < maxX; x++){
                 
                 TreeInstance tree = new TreeInstance();
                 
                 float height = terrain.SampleHeight(new Vector3(x,0,z));
                 
                 if(height > res*0.2){
                     
                     if(Random.value > .6){
                     
                         float r = Random.Range(80f, 120f),
                               g = Random.Range(100f, 150f),
                               b = Random.Range(20f, 80f);
                         
                         tree.color = new Color(r,g,b);
                         tree.heightScale = Random.Range(0.5f, 2f);
                         tree.widthScale = Random.Range(0.75f, 1.25f);
                         tree.position.Set(x, height, z);
                         tree.prototypeIndex = Random.Range(0, treeTypes);
                         
                         terrain.AddTreeInstance(tree);
                     }
                 }
             }
         }
     }

I know this is incredibly vague, but I know it's this bit of code because it runs fine when I comment out the function call. I am at a complete loss at this point, if anyone has a tiny bit of knowledge on this I would greatly appreciate it.

On a side note for some reason this places all the trees in the same place despite having the positions changed... Any ideas why? I have a feeling it's the way I'm instantiating the trees, but I don't know why that wouldn't work.

Comment
Add comment · Show 8
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 $$anonymous$$ · Mar 03, 2013 at 02:02 PM 0
Share

Are you calling it inside a coroutine?

avatar image Rett_ · Mar 03, 2013 at 02:14 PM 0
Share

For default terrain the loop executes 4 milion times, creating around 2.4 milion trees (a bit too much for most computers to handle). What is your terrain size?

avatar image Dunlain · Mar 03, 2013 at 02:19 PM 0
Share

Also I think I'm misusing SampleHeight here, but without proper documentation it was sort of a stab in the dark.

avatar image Aria-Lliane · Mar 03, 2013 at 02:32 PM 0
Share

I agree with Rett_ it's just too much trees to handle, have you tried this code with a limited small number of trees?

Besides that all i can think of for now is to make sure not to call this in a monobehavior.

avatar image Dunlain · Mar 03, 2013 at 02:53 PM 0
Share

I'm calling it inside the OnGui Function, which might be dangerous... I haven't read the full doc on it since I've been focused on actually getting in content before efficiency at this moment. Basically, I have 2 classes for Terrain Generation, and this function is in the higher level script that adds trees and GameObjects and the other one generates a TerrainData object. Thanks for the ideas though, I'm working on this on my own so my thoughts stagnate at times.

Show more comments

0 Replies

  • Sort: 

Follow this Question

Answers Answers and Comments

11 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

Related Questions

Invisible trees? 1 Answer

Can Tree with terrain system be set up random rotation? 1 Answer

Tree creator and terrain editor 0 Answers

colliders moving in wind 1 Answer

S.O.S: Tiny Tree Issues. 3 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