Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


OverlapSphere(Vector3, float, Collider[], int, QueryTriggerInteraction)

Computes and stores colliders touching or inside the sphere into the provided buffer.
Read time 1 minuteLast updated 12 days ago

Definition

  • Type: Method
  • Namespace: UnityEngine
  • Assembly: UnityEngine.PhysicsModule
public int OverlapSphere(Vector3 position, float radius, Collider[] results, int layerMask, QueryTriggerInteraction queryTriggerInteraction)

Parameters

position

Center of the sphere.

radius

Radius of the sphere.

results

The buffer to store the results into.

layerMask

A Layer mask that is used to selectively filter which colliders are considered when casting a sphere.

queryTriggerInteraction

Specifies whether this query should hit Triggers.

Returns

Type

Description

intThe number of colliders detected that overlap with the sphere and were stored in the
results
array. The return value cannot exceed the size of the
results
array.

Remarks

Additional Resources: Physics.OverlapSphereNonAlloc