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
0
Question by RoloJo · Nov 14, 2013 at 06:13 PM · colliderterrainphysx

Could not create tree colliders. Maybe there are more Trees then PhysX can handle?

Hi all,

I have recently been exploring methods to create trees on the terrain via script.

         Terrain terrain = (Terrain)GameObject.FindObjectOfType(typeof(Terrain));
         tempInstance=terrain.terrainData.treeInstances[0];
     
         for (int i=0;i<100;i++)
         {
             for (int j=0;j<100;j++)
             {
                 tempInstance.prototypeIndex = 0;
                 tempInstance.color = new Color (1, 1, 1);
                 tempInstance.lightmapColor = new Color (1, 1, 1);
                 tempInstance.heightScale = 1;        
                 tempInstance.widthScale = 1;
                 tempInstance.position = new Vector3 ((float)i/100, 0, (float)j/100);    
                 terrain.AddTreeInstance (tempInstance);        
                 terrain.terrainData.SetHeights(0, 0, new float[,] { { } });
                 terrain.Flush ();
             }
         }

The problem is that the collider disappears when I run the script. As such the character just falls through the terrain. The trees are created ok. If I stop the game mode, disable the script and play (with all the trees still three) the collider is there and works just fine. Furthermore if I create only 100 trees (ie set i,j=10) the collider works just fine. Any idea of how to fix this?

Thanks

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

2 Replies

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

Answer by RoloJo · Nov 20, 2013 at 03:35 PM

Figured out my problem.

If you dont delete the trees that already exist on the map you constantly just add trees with the above script. Eventually you exceed the maximum number of trees allowed on the map which crashes the PhysX. Instead use the following code which just "redefines" where trees are, how many etc:

 Terrain terrain = (Terrain)GameObject.FindObjectOfType(typeof(Terrain));
 
         tempInstance=terrain.terrainData.treeInstances[0];
         tempInstance.color = new Color (1, 1, 1);
         tempInstance.lightmapColor = new Color (1, 1, 1);
         tempInstance.heightScale = 1;        
         tempInstance.widthScale = 1;
         ArrayList instances = new ArrayList();
         for (int i=0;i<10;i++)
         {
             for (int j=0;j<10;j++)
             {
                 tempInstance.position=new Vector3 ((float)i/10, 0, (float)j/10);    
                 instances.Add(tempInstance);
             }
         }
 
         terrain.terrainData.treeInstances = (TreeInstance[])instances.ToArray(typeof(TreeInstance));
         terrain.terrainData.SetHeights(0, 0, new float[,] { { } });
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
avatar image
0

Answer by MalachiteBR · Nov 14, 2013 at 07:39 PM

Well, Im not home so I cant test it. But first of all, I think you should move you treeInstance declaration inside the for loop and also make it var treeInstance = new TreeInstance(); instead of the first tree.

As for the position I think you should use like fixed x, or y, and then increment the x/y according to the loop, if you are trying to make some kind of tree line.

The problem is that I dont know if it will make a copy of this instance tree or it will use the same instance, that will cause many problems.

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

17 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

Related Questions

Terrain Tag OnControllerColliderHit not showing 0 Answers

Creating Box Collider On Specific Terrain Textures 1 Answer

Animated Object falls through elevated terrain 0 Answers

How to create a ground/terrain/floor that won't respond to gravity or objects falling on it? 1 Answer

Solution for the FPS Character Controller falling through terrain 2018.3 Version 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