- Home /
Painted trees do not take their prefab's collider
The trees I painted on my landscape do not have colliders, despite the fact that Unity is painting a prefab which has a collider. In fact, if I place that same prefab on the landscape directly, the tree does have a collider. It's only when I paint the trees does this problem occur. Is it something about painting that makes everything collider-less?
Answer by zmar0519 · Apr 22, 2011 at 07:50 PM
I'm not sure how to do this either, but you could, in the terrain collider script, check generate tree colliders. Or, you could download the terrain assets on the unity website and use the sicomore with collider prefab for a tree. Hope it helps!!! :)
Thanks, but I did try those. I guess I'm stuck placing the trees by hand.
Ah, I got it solved! The adding prefab to the painted tree option finally worked. Don't know why it didn't do it before....
Answer by GeorgeRigato · Nov 12, 2012 at 01:28 PM
I've done both. Capsule collider COMPONENT in a tree and for other trees I have added two or more GameObjects Capsule with collider to the tree prefab.
only the collider component generate a proper collision.
Maybe if all the capsules inside the trees have a rigidboy attached, the collision with a standard unity's FPS character would work properly?
I'll go and test that.
Answer by Twistyd · Oct 13, 2018 at 09:09 AM
Ancient as this is I had the same issue, I resolved it by tagging the terrain. Sorry for the necromancy but if it can help someone else out then it's worth it.
TL|DR
It's not the trees!
Try using a tag on the terrain and then have the collision detection look for that tag, like so;
void OnCollisionEnter (Collision other){
// If the entering collider is a tree...
if(other.gameObject.tag == "Tree"){
Debug.Log ("Ow");
}
}
Initially I'd tried all I'd found online to try and fix it, I even tried tagging the trees with a Tree tag, re-prefabbing them, and then trying to repaint the re-prefabbed tree but nothing worked.
Last night I accidentally gave my terrain the Tree tag and boom, it worked, all sorted.
My collision code is:
void OnCollisionEnter (Collision other){
// If the entering collider is the enemy...
if (other.gameObject.tag == "Enemy") {
hit = true;
}
// If the entering collider is a tree...
if(other.gameObject.tag == "Tree"){
Debug.Log ("Ow");
}
}
My thinking is that the tree colliders, which are part of the terrain, are actually seen as the terrain. This might not be a workable workaround if you plan on having a character walk on the ground and receive damage if they hit a tree but might be useful for someone.
Hope it helps.
Your answer
Follow this Question
Related Questions
Making custom trees with animation work with unity terrain 0 Answers
Terrain tree colliders as triggers 2 Answers
Cannot place trees on terrain 0 Answers
Can't use tree brush tool 0 Answers
OnTriggerExit not called for Tree painted on Terrain 0 Answers