Skip to main content

Nearby Interactables Scanner

NAMESPACEMyDreamGameStudio.InteractAnything
MENU PATHInteraction System > Utilities > Nearby Interactables Scanner
COMPATIBILITYUnity 6.0+
DOC VERSION

A high-performance spatial sensor that continuously scans for interactables within a specific radius. It filters candidates based on viewing angles and line-of-sight, then sorts them by distance so the closest valid target is always exposed first.

This component is a pure sensor. It never focuses, selects, or interacts with anything on its own. It simply provides a clean, sorted list of AvailableInteractables for other systems (like the RadiusInteractor or a UI compass) to read from. It forces a [DefaultExecutionOrder(-100)] to ensure its spatial data is perfectly up-to-date before any interactors run their logic.


Editor Interface​

NEARBY INTERACTABLES SCANNERSPATIAL SENSORPHYSICS OVERLAPContinuously scans, filters, and sorts nearby candidates within a search sphere, exposingthem closest-first.SPHERE DETECTION✦ Self As OriginDetection Origin PointNone (Transform)Scan Radius (m)3Max Colliders (Buffer)16Interactable LayersEverythingFIELD OF VIEW FILTERAngle Filter (optional)Enable FOV FilterLINE OF SIGHT FILTERLine of Sight Filter (optional)Require Line of Sight

Configuration Variables​

Sphere Detection​

Detection Origin Point
TransformDef: Self
The center of the search sphere. If left empty, it defaults to the transform this component is attached to.
Scan Radius (m)
floatDef: 3.0
The size of the Physics.OverlapSphere query. This dictates the absolute maximum distance an interactable can be detected.
Max Colliders (Buffer)
int sliderDef: 16
The capacity of the internal non-allocating array. If you have 20 interactables clustered tightly together but this is set to 16, the engine will only process the first 16 it finds. Increase this value (up to 128) if you have incredibly dense scenes.
Interactable Layers
LayerMaskDef: Everything
The physics layers the sphere query evaluates. Restricting this to a dedicated 'Interactable' layer drastically improves performance.

Filters (Optional)​

Enable FOV Filter
boolDef: False
If enabled, targets are rejected if they fall outside a specific forward-facing angle. Activating this reveals additional fields for 'Max Angle' and an optional 'Angle Reference' transform.
Require Line of Sight
boolDef: False
If enabled, the scanner casts a ray toward the target. If the ray hits a blocking layer before reaching the interactable, the target is rejected. Activating this reveals a 'Line of Sight Blockers' LayerMask.

The Sensing Pipeline​

Every frame, the scanner executes a highly optimized pipeline to populate its AvailableInteractables array:

  1. Overlap Query: Calls Physics.OverlapSphereNonAlloc to grab all colliders in the radius without generating garbage.
  2. Component Resolution: Looks for an Interactable component on the collider or its parents.
  3. Filtering: Rejects targets that have IsInteractable set to false, fail the FOV angle check, or are blocked by geometry (if Line of Sight is required).
  4. Sorting: Sorts the surviving candidates by absolute distance to the origin.
  5. Exposure: The closest valid target is exposed via the Closest property.

Logic Visualization​

The radar simulation below demonstrates how the scanner evaluates targets based on FOV and Line of Sight constraints.

Scan RadiusLOS BLOCKERValid TargetBLOCKEDOut of FOV