Unity crashes with too many trees per terrain

I’ve confirmed that if there are too many tree instances per terrain object, Unity blows up. It doesn’t seem to make any difference what the total “global” number is, so it’s evidently caused by a limit for each terrain. It’s difficult to determine the magic number that causes a crash, or why it crashes. Does anyone know what the maximum # of tree instances is? They are stored in an array called TreeInstance[ ] which presumably has a limit.

This is not exactly it. I ve placed 300k default trees (1000 tris) to 2000*2000 terrain and no problem. But once the tree has collider, it crashes around 85k when pressing play (80k was OK).
There is probably some connection to number of polygons too, as more complex trees from tree creator are (2000 tris) causing crash sooner (around 60k).
This wouldnt be problem for such high numbers, BUT I am able to crash unity with FAR less trees (15-20k). It depends on configuration, I am still fighting to figure exactly why. And this is big problem, because there is no chance to have nice forest with such low numbers. Any performance settings like maximum tree meshes, or visibility makes no difference.

Ok, so other discovery. Multiple terrains adding to “crash limit pool”. Even if one terrain is OK (not reached crash limit), two similar terrains crash. So under current cirmustances it is not possible to make any serious world without writing own terrain engine. Only chance is not using colliders on trees. Having 50k trees/bushes for for example 4x 2000*2000 terrains (worst scenario when dymically loading) means 12k on each, which is joke, not forest. Unity terrain engine is piece of junk anyway (we LOVE terrain init and lags it is causing), but one would expect at least to not crash.

Good testing unity team!

I am quite scared, that nobody is confirming this (it is very easy to replicate). Is there anyone, who is doing games with unity?

Does it crashes when you press play or when you play the game?

Did you check if you simply ran out of memory or graphics memory?

Terrains and trees are pretty beefy on that end.

When pressing play.

There is no out of memory message (which is very typical for unity, but this is not that case).
And ammount of tree does not matter, 300k tree is insane number and it is NOT crashing. It is crashing only when trees have collider. Limit is cca 70-80k of trees (not 65536, this I was checking), which is not good. For one terrain no problem, but 4 terrains are thus limited to 20k and this is bad. AAA forest requieres around 50k trees/bushes/etc…for 20002000 terrain. We have game made from 20002000 terrains, which are streamed (so 4 terrains is maximum).

When I turn off tree colliders, everything is OK, speed is OK, memory usage is OK. So this is obvious bug.

Interesting is, that for crashing is enough to have mesh collider on the tree from tree creator (and few thousands of such trees). That collider even dont have to be active. There is something really rotten. Yesterday I was able to regularly crash Unity with cca 10k of tree creator trees, where only cca 1 thousand had non active collider. When i deleted that collider, no crashes anymore.

I was curious, if 3.5 fixes this problem. Good news is, that scene with for example 100k trees is not crashing. Bad news is, that in case of more trees colliders are not working! (few trees OK, more trees not working).

WTF?? Guys, are you serious? Are you calling this fix?!

I’ve noticed that Unity doesn’t seem to actually create the number of trees you choose with the “mass place trees” function. I’ve tried it with the default number of 1000, or higher like 5000, but then if I output the TreeInstances[ ] array to a text file when I actually launch the game, there are only around 200 trees, no matter what I chose in Mass Place Trees. I can also tell just looking at the terrain in the editor that there are only a few hundred trees. I’m thinking that the number you choose in Mass Place Trees is just an upper limit, and that Unity chooses some arbitrary number lower than that to fill the terrain with trees without too much overlap.

However, I’ve seen that when rebuilding the TreeInstance array at runtime, Unity will often crash, regardless of the number of trees I’m putting in. Also, as I posted in a new thread right now, it doesn’t place the colliders correctly when adding trees at runtime. I’d guess that there must be some kind of disconnect between the TreeInstance and its collider that both causes the missing colliders and the crash when placing many trees with colliders.

I don’t recall whether this was addressed sooner, but how close together are your trees, and (more importantly), how close together are your colliders? If your tree amount is really high and you have a lot of trees side by side at runtime with slight overlap of colliders, the trees will explode apart from one another. That much movement is probably enough to crash a game. Obviously, I’m over a year off with this response, but I was having the same issue until I found this thread and started really thinking about trees and colliders.

I believe there is a PhysX limitation on the number of colliders and the tree colliders count towards this limit. From the docs: “Note that the PhysX engine used by Unity only handles a maximum of 65536 colliders in a scene. If you use more trees then that (minus the other colliders already in the scene), then enabling tree colliders will fail with an error.”