Currently I’m working on a semi-random survival game, made with Unity 5.6 on Linux.
The game is built on different terrain tiles, spawning as the player progresses through the world.
Each tile (just a prefab) is filled with trees (again, prefabs) on random locations. For visual coolness the trees are spawned above the camera view, after which they fall to the terrain tile thanks to a Rigidbody attached to each tree.
So far, so good.
Of course, with each tree’s position being random, trees will be spawned at the same spot, and end up being placed on top of each other.
Right now I’m sending down a Raycast out of each tree which gives me the tag of the object directly underneath it, and if this tag is not ‘terrain’ (but a tree), the tree will choose a new location and try again.
The problem with this is that the Raycast has to be as wide as the tree itself, so I have to use SphereCast to send down the Ray.
For this, I need to know the width of the GameObject, which is something I really cannot understand how to do.
I’m kinda confused with Unity’s concept of local scales, world scale, renderer and collision boundaries and so on.
Is there a simple and generic way to get the needed thickness of the SphereCast?
Attached: two trees, besides a lovely lake, where one is stacked on top of the other one.

Renderer.bound gets you the bounding box of the tree, but let me give you a suggestion
Once I used procedural forest generation, and what worked for me very well, was what I call forest spreading
I choose a location for a tree, and put it down, and while there wasn’t enough trees, I choose a random tree and planted a new tree in a random location around it between 3 and 5 meters, this is good because:
a.) it really looked realistic with the right settings, it was a forest, not just random trees scattered around
b.) if I wanted to check, whether a tree intersected with another one, I just went around the trees and looked for one, that’s too close to it, by checking the square distance between the new tree and the old ones, and if that happened, I just voided the tree
c.) You can get rid of cluttering, just by saying, that a tree can only have a single offspring
d.) If I just voided the tree, and I didn’t try to re-create it, it created random sized forests
e.) If you’re really looking into realism, you can simply implement a grow - reproduce - die system, that relies on a lot of different factors, and works pretty well without being too time consuming
This sounds like a real good idea, hadn’t thought of that approach, but indeed it could make things a lot more realistic.
Right now I’m fiddling with a fixed number of trees per tile, which looks indeed like random trees and not like a forest.
I’ll have a look at this technique the following days!