Checking for Collisions Before GameObject Creation

Suppose that I want to create an object (or set of objects) only if the space they would occupy does not contain any other objects. How can I check for this?

(I'm aware of Physics.OverlapSphere(), but that's only any use if the GameObjects are all spheres, or at least have spherical colliders, which is not in general the case.)

I think the best way to do it would be to have an invisible instance which you position at the location, and check if that invisible instance is colliding. If that instance isn't colliding then create a real instance. That allows you to create any shape/size collider you need.

I had a similar problem and resolved it using this

`Physics.OverlapSphere(position, radius);`

That'll return an array of Colliders that are intersecting or touching a Sphere at position with the given radius.

Other functions (like Physics.CapsuleCastAll) also sound very promising, but didn't work out for me. For some reason they didn't return collisions properely.


Instantiate prefab but make all collider triggers. Check for trigger state.