- Home /
Tree colliders not working.
Hey I have been having trouble with adding tree colliders in my map. I have the "Create tree colliders" option checked, and have the "is triggered" box unchecked. I have no idea how to fix it, thank you.
Did you check the layer of the trees and the layer collision matrix?
Answer by ffxz7ff · Jan 11, 2014 at 01:44 AM
I know this topic is old, but it's also unanswered and I struggled for a few hours tonight, trying to solve the same problem. Am I assuming correctly that you were trying to add trees to an existent terrain after its creation?
The problem is that the Collider doesn't update automatically. After adding the trees, I did this manually by doing the following:
terrain.GetComponent-TerrainCollider-().active = false;
terrain.GetComponent-TerrainCollider-().active = true;
(replace - with pointed brackets, can't write this here)
And now it works properly. There might be a better way to do this, but this is what works for me so far.
Why not format the code?
terrain.GetComponent<TerrainCollider>().active = false;
terrain.GetComponent<TerrainCollider>().active = true;
You can do this by highlighting all your code, then clicking the 10101 button at the top of the edit window.
Ah alright, thank you. I tried to format it properly but for some reason I couldn't get it to work last night. :)
working in unity 2021.1 too. Add it to awake function and attach to terrain object.
Answer by the_Simian · Jul 23, 2012 at 04:17 PM
I've had this problem. All you need to do is add a prefab for the tree, and then add a capsule collider for the trunk of the tree. This way the "leaves" can still be walked through, but the trunks will prevent you from walking through.
Heres the process:
Find the tree you want in the Project panel.
Drag it out as a prefab onto your scene anywhere
Select the tree, then add: [Components menu -> under Physics, -> capsule collider]
Set the radius of the collier to match the trunk (for me it was about 0.7 on the radius)
Make a new prefab, by dragging this "capsule collider'd" tree back to the original
use this new tree in the terrain Painter.
Place a few trees, and you should be ready to go! Can't walk through the trunks now!
If the tree has any other large branches you don't want to be able to walk through follow the same process and add additional colliders on them.
Its easy!
It's not necessary to create new prefab, just press "apply" button at the top of object inspector
@dimmduh thank you for the update. $$anonymous$$y answer is 2-3 years old now, and there are probably better ways now.
Answer by AnoyRC · Jan 18, 2018 at 06:56 PM
Another easy way: 1.Select the prefab from where you have selected the tree. 2.keeping the prefab selected in asset browser, in inspector, add component mesh collider or box collider or capsule collider and it's done...
Answer by ThatUnityNoob · Jul 23, 2012 at 03:39 PM
I have had the same problem before...What I did that ended up working was I put down the prefab of the "tree" I was using, then I put a box collider on it and positioned it corectly around the tree. Then I saved it as a diffent prefab and used it as the tree for the terrain. It worked fairly well.
Your answer
![](https://koobas.hobune.stream/wayback/20220613074440im_/https://answers.unity.com/themes/thub/images/avi.jpg)