- Home /
Tree collisions not working with painted tree (Unity 2019.4.28f1),Terrain tree colliders not working
Hi everyone,
I know this question has been asked many times already, but most of them occurred long ago or didn't have an answer that would help.
For context, our project is on Unity 2019.4.28f1. We are using the Terrain tool to place trees on a map. I am trying to use the OnTriggerEnter/Exit for audio purposes. It works if I use the prefab directly in the world, but not as a painted tree.
Here's what I've read and done so far:
Use trigger and collider w/ rigidbody
Made sure Layers are set up properly for collision (works as a prefab anyway, just not painted)
Made sure Tree collision is enabled on Terrain
Moved the terrain object to 0,0,0 (it is slightly off origin, but moving it to 0,0,0 didn't fix it)
Refresh the trees in the Terrain tool
Use Capsule Colliders on tree
Is there any other things I might have missed that would explain why everything works when trees are used as prefabs, but not when painted?
Thanks everyone !
Answer by davegagne · Feb 11 at 01:58 PM
Alright, I'll answer my own question for anyone who might be looking at their screen scratching their head at the same problem (and also to keep breadcrumbs when we'll face that issue again in two years).
It only took half a day, a designer and two programmers, but we figured it out.
I was calling code to check for a Tag collision with Tag 'X' on my Tree prefabs. However, the terrain the trees were painted on was on Tag 'Y'. What we realized is that once you paint those trees, they no longer are on Tag 'X', but will rather get the tag from the terrain it was painted on.
Solution, simply check for layers instead as apparently this is not inherent from terrain (which is... great !). In our case, since we are not using the terrain collision, we just put the terrain on another layer and disabled collision with our character. Done. You can now collision check with the trees, no issues.
Have fun !
Your answer
Follow this Question
Related Questions
Can't use tree brush tool 0 Answers
Terrain Tree Prefab Orientation Prob 3 Answers
Disappearing Trees 0 Answers
Randomize trees for terrain painting 2 Answers
alternative to the alpha utility photoshop actions found in docs 1 Answer