- Home /
Terrain addTreeInstance crash
I seem to have a problem with creating trees on a terrain object using terrain.AddTreeInstance(instance); function because it crashes unity on play.
I got multiple terrain objects generating at runtime and I'm trying to add one tree to the corner of each terrain with this code:
NOTE: I'm creating the trees before actually setting the terrainData to the terrain so it does update the terrain after my trees get added.
var tmp : TreeInstance = new TreeInstance();
tmp.heightScale = 1.0f;
tmp.widthScale = 1.0f;
tmp.prototypeIndex = 0;
tmp.color = Color.white;
tmp.position = new Vector3(0.0f,heightMap[0,0],0.0f);
terrain.AddTreeInstance(tmp);
Also I have added one tree prefab to the treeprototypes array earlier in the code and it does show up in the inspector if I do not create trees this way.
Does anyone else experience this or am I using the AddTreeInstance function wrong?
Answer by multinfs · Jul 05, 2014 at 03:23 PM
Well this had quite an easy fix, I had to add the trees After I add the terrainData to the terrain.
Now I just have to fix the trees generating completely black..
Your answer
Follow this Question
Related Questions
Instantiate 697283 trees by script? Crash! 2 Answers
Stuck on how to get trees to show after calling CreateTerrainGameObject() 0 Answers
Invisible trees? 1 Answer
Terrain Tree Placement 0 Answers
Tree billboard with tree creator shaders 0 Answers