# OverlapSphereNonAlloc(Vector3, float, Collider[], int, QueryTriggerInteraction)

> Computes and stores colliders touching or inside the sphere into the provided buffer.

## Definition

* **Type:** Method
* **Namespace:** [UnityEngine](/engine/6000.7/script-reference/unityengine.md)
* **Assembly:** UnityEngine.PhysicsModule

```csharp
public static int OverlapSphereNonAlloc(Vector3 position, float radius, Collider[] results, int layerMask, QueryTriggerInteraction queryTriggerInteraction)
```

### Parameters

**** (\[Vector3]\(/engine/6000.7/script-reference/unityengine/vector3)): Center of the sphere.**** (\[float]\(https\://learn.microsoft.com/dotnet/api/system.single)): Radius of the sphere.**** (\[Collider\[]]\(/engine/6000.7/script-reference/unityengine/collider)): The buffer to store the results into.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): A Layer mask defines which layers of colliders to include in the query.**** (\[QueryTriggerInteraction]\(/engine/6000.7/script-reference/unityengine/querytriggerinteraction)): Specifies whether this query should hit Triggers.

### Returns

| Type                                                       | Description                                                       |
| ---------------------------------------------------------- | ----------------------------------------------------------------- |
| [int](https://learn.microsoft.com/dotnet/api/system.int32) | Returns the amount of colliders stored into the `results` buffer. |

### Remarks

Does not attempt to grow the buffer if it runs out of space. The length of the buffer is returned when the buffer is full. Like [Physics.OverlapSphere](/engine/6000.7/script-reference/unityengine/physics/overlapsphere.md), but generates no garbage.

Additional Resources: [Physics.AllLayers](/engine/6000.7/script-reference/unityengine/physics/alllayers.md), [ Use of layers in Unity](/engine/6000.7/manual/working-with-gameobjects/layers/use.md)

### Examples

```csharp
using UnityEngine;

public class ExampleClass : MonoBehaviour
{
    // Declare hitColliders as a reusable field.
    private Collider[] hitColliders;

    // Set the maximum number of colliders that can be detected at once.
    private const int maxColliders = 10;

    void Awake()
    {
        // Initialize the array just once.
        hitColliders = new Collider[maxColliders];
    }

    void ExplosionDamage(Vector3 center, float radius)
    {
        // Reuse the pre-allocated array for Physics.OverlapSphereNonAlloc.
        int numColliders = Physics.OverlapSphereNonAlloc(center, radius, hitColliders);

        // Iterate through detected colliders and send the AddDamage message.
        for (int i = 0; i < numColliders; i++)
        {
            hitColliders[i].SendMessage("AddDamage");
        }
    }
}
```
