- Home /
Instantiated terrain tree collision not working
Hello all!
I'm trying to make a game that loads prefab terrains at run time, triggered by various conditions (such as where the player camera is). I noticed that if I "preload" the terrain (meaning the terrain is already in the scene when game starts as opposed to instantiating prefab), then the tree collision and terrain collision are both working.
However if I instantiate the terrain prefab during run time, terrain collision works but tree collision doesn't. The way I test it is by moving a rigidbody gameobject with AddForce command, and let it fly towards the tree. The object simply passes through the tree but will bounce upon touching the terrain.
Is this a known issue?
Thanks! :)
I just tested another way by manually place the tree prefab in the scene, put it under the terrain gameobject and save the whole thing as a prefab (terrain + many trees). This time after the terrain and trees are instantiated in the scene, collision worked fine.
It seems like there may be a unity bug where when the terrain is instantiated, the tree colliders are not added to the terrain. I cannot use the workaround of manually place trees one by one since I still depend on unity terrain system to add wind and billboard effect to the trees.
Answer by shoeshine1984 · Dec 08, 2013 at 09:49 AM
I figured it out. When you instantiate the terrain, you need to reset the terrain collider like this:
newTerrain.collider.enabled = false;
newTerrain.collider.enabled = true;
And then the tree colliders will be generated. Hope Unity puts this in the documentation one day!
This the dumbest, stupidest advice ever. It is even dumber and stupider that it actually works! Thank you!!!!!
Your answer
Follow this Question
Related Questions
Make a simple tree 1 Answer
The tree "Tree" couldn't be instanced because the prefab contains no valid mesh renderer. 1 Answer
Trees painted by the terrain editor are too small 2 Answers
Why does my Tree on Terrain not look like the Original Prefab it was made of? 0 Answers
Terrain Tree Prefab Orientation Prob 3 Answers