Documentation index for AI agents (llms.txt) A Markdown version of every page is available: request the page's source under /docs/, follow the "alternate" link in this page's head, or start from /llms.txt.
Visual Script logo Manual

Overlap Sphere 3D#

Physics 3D / Overlap Sphere 3D

  • Can Read

  • Cannot Write

Description#

Returns all 3D colliders that overlap with a sphere

Parameters#

Name Description
Point The center point of the sphere in 3D space
Radius The radius of the sphere
Layer Mask Filter to check objects only on specified layers
Use Triggers Whether to check for Colliders marked as triggers or not

Code#

using System;
using System.Collections.Generic;
using UnityEngine;
using VisualScript.Icons;

namespace VisualScript.Runtime
{
    [Get]
    
    [Title("Overlap Sphere 3D")]
    [Category("Physics 3D/Overlap Sphere")]
    
    [Description("Returns all 3D colliders that overlap with a sphere")]
    [Image(typeof(IconSphereOutline), ColorTheme.Type.Lime, typeof(BadgePhysics))]
    
    [Parameter("Point", "The center point of the sphere in 3D space")]
    [Parameter("Radius", "The radius of the sphere")]
    [Parameter("Layer Mask", "Filter to check objects only on specified layers")]
    [Parameter("Use Triggers", "Whether to check for Colliders marked as triggers or not")]
    
    [Keywords("Inside", "Sphere", "Round", "Ball", "3D")]
    
    [Serializable]
    public class TypeCollectionGameObjectsPhysics3DOverlapSphere : TypeCollectionGameObjects
    {
        private static readonly Color GIZMO = new Color(0f, 1f, 0f, 0.25f);
        
        private static readonly Collider[] HitsBuffer = new Collider[128];
        
        [SerializeField] private GetVector3 m_Point = new GetVector3();
        [SerializeField] private GetNumber m_Radius = new GetNumber(1f);
        
        [SerializeField] private LayerMask m_LayerMask = Physics.DefaultRaycastLayers;
        [SerializeField] private GetBool m_UseTriggers = new GetBool(false);
        
        public override void Get(Args args, List<GameObject> values)
        {
            Vector3 point = this.m_Point.Get(args);
            float radius = (float) this.m_Radius.Get(args);
            
            QueryTriggerInteraction triggerInteraction = this.m_UseTriggers.Get(args) 
                ? QueryTriggerInteraction.Collide 
                : QueryTriggerInteraction.Ignore;
            
            int numHits = Physics.OverlapSphereNonAlloc(
                point,
                radius,
                HitsBuffer,
                this.m_LayerMask,
                triggerInteraction
            );
            
            GizmosManager.Sphere(point, Quaternion.identity, radius, GIZMO, GizmoMode.Outline, 0.25f);
            
            values.Clear();
            for (int i = 0; i < numHits; ++i)
            {
                Collider collider = HitsBuffer[i];
                if (collider != null) values.Add(collider.gameObject);
            }
            
            Array.Clear(HitsBuffer, 0, numHits);
        }

        public override string ToString()
        {
            return $"Overlap Sphere 3D at {this.m_Point} radius {this.m_Radius}";
        }
        
        protected override SubscriptionMode Subscription => SubscriptionMode.OnChange;
    }
}
Visual Script logoVisual Script © Catsoft Works 2026. All rights reserved.