Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Jademyr · Mar 09, 2010 at 11:11 PM · colliderterraindestroytreeremove

Remove trees dynamically - stuck with collider

I'm trying to remove trees dynamically.

I can remove the visible mesh/tree with TerrainData.treeInstances.RemoveAt(n) But I'm stuck with the colliders of the destroyed trees.

I've run out of ideas. Any one have a solution for this? Is it possible?2

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

3 Replies

· Add your reply
  • Sort: 
avatar image
3

Answer by duck · Apr 14, 2010 at 02:26 PM

I'm surprised that RemoveAt works at all for you with the treeInstances array, since it's a built-in array and doesnt' (as far as I know) support the RemoveAt function.

When I have modified or set the treeInstances array in the past, I've always built or modified them in a variable sized array (such as an ArrayList or List), and then dumped the entire new array back into terrainData.treeInstances as a whole, like this:

// get a copy of the trees, into a new dynamic collection List<TreeInstance> newTrees = new List<TreeInstance>(terrainData.treeInstances);

// modify the collection newTrees.RemoveAt(n);

// replace the trees back into the terrainData as a built-in array terrainData.treeInstances = newTrees.ToArray();

And also, make sure you are calling:

terrainData.RecalculateTreePositions();

after modifying the tree instances array.

Note
Some of these functions are undocumented. Any future updates of the unity engine might change or remove these functions from the API. This means your project may not work in future versions of the Unity editor, and webplayer builds may not work with future versions of the plugin.

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
1

Answer by jc_lvngstn · Nov 02, 2011 at 01:04 AM

Here is how:

         // Now refresh the terrain, getting rid of the darn collider
         float[,] heights = terrain.GetHeights(0, 0, 0, 0);
         terrain.SetHeights(0, 0, heights);

You also may need to disable and reenable the terrain collider.

Here is a thread that gives more details: http://forum.unity3d.com/threads/110354-Finally-Removing-trees-AND-the-colliders

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
-1

Answer by KHopcraft · Mar 30, 2010 at 09:55 PM

Sounds kind of like a bug. Try submitting a bug report.

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 duck ♦♦ · Apr 14, 2010 at 02:29 PM 1
Share

These are undocumented functions - and therefore officialy unsupported, so a bug report is not applicable in this case.

avatar image KHopcraft · Apr 21, 2010 at 04:37 PM 0
Share

Oh, thank. I see the problem. Sorry.

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

1 Person is following this question.

avatar image

Related Questions

Destroy Terrain Trees And Their Colliders 0 Answers

Picking Trees with Mouse 5 Answers

Removing terrain tree at runtime not updating collider 1 Answer

Billboard system 1 Answer

Colliding with trees using mesh colliders 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