check if there are no object inside a trigger

I’ve got Quad attached to the camera and is above it, with a mesh Collider attached to it, I’m making a vertical platformer, and would like prefabs to be instantiated when there are no objects inside that trigger. how can i check if there are no objects in a trigger?

Your objects should contain triggers as well to cooperate with other trigger, and if they do just use this:


P.S. And just for the sake of completeness - alternatively you can always maintain sort of a “contained triggers” list yourself using this 2 functions:



There are a few static functions in the Physics class that might solve this problem, depending on the shape of the area you are searching, the size of the area, and the size of the objects you are looking for.

OverlapSphere will return an array of all colliders that are in, or touching, the sphere. This one would work best if a sphere is suitable for the sizing.

CheckSphere is similar, but returns a bool indicating the presence of a collider and may not check inside the sphere.

RayCast casts a ray and returns information on what it hits. But you would need an array of rays cast, and this could be computationally expensive, depending how large of an area you are looking at and how small the objects you are looking for will be.

SphereCast casts a sphere along a ray, which is essentially a capsule version of SphereCheck.