Skip to main content

Cursor Interactor

NAMESPACEMyDreamGameStudio.InteractAnything
MENU PATHInteraction System > Interactors > Cursor Interactor
COMPATIBILITYUnity 6.0+
DOC VERSION

Interacts with whatever the cursor is actively pointing at. This interactor casts a ray from the camera through the current mouse or pointer position each frame to detect focus targets. It is engineered specifically for top-down, RTS, simulation, or point-and-click interaction models.


Editor Interface​

CURSOR INTERACTORPOINTER RAYCASTRTS / POINT-CLICKPROJECTION SETTINGS✦ Auto-Wire CameraSource CameraNone (Camera)Ray Distance (m)100Interactable LayersEverything

Configuration​

Source Camera
CameraDef: Camera.main
The camera matrix used to project the cursor ray. If left empty, the component will automatically search for Camera.main during Awake().
Ray Distance (m)
floatDef: 100.0
The maximum depth the raycast will travel to detect interactables. Ensure this is tuned to your camera's far clipping plane.
Interactable Layers
LayerMaskDef: Everything
Physics layer mask filtering which objects the cursor can hit. Highly recommended to restrict this to a dedicated 'Interactable' layer to save physics processing time.

Target Resolution Pipeline​

When the CursorInteractor fires its raycast against the world, it uses a specific fallback hierarchy to resolve targets. This allows you to build complex prefabs without duplicating scripts.

  1. Direct Hit: It first checks if the hit Collider has an Interactable component directly attached.
  2. Parent Fallback: If not found, it checks GetComponentInParent<Interactable>(). This is extremely useful for setup; you can place a large trigger collider on a drawer handle, but keep the actual Interactable script on the root Drawer object.
  3. Spatial Data Override: If no valid interactable is found, the system still caches the exact point on the ray boundary. This ensures that if the player is currently operating a Drag or Push/Pull mechanic, continuous spatial data is still fed to the active component even if the cursor temporarily slips off the mesh.

Runtime API​

The interactor exposes public configuration methods so external modules (like the ExaminePanel or custom input switchers) can hot-swap targets and cameras without requiring duplicate interactor components in your scene.

// Overrides the camera driving the screen-point raycast
public void SetSourceCamera(Camera camera);

// Restricts or expands which physics layers can be targeted at runtime
public void SetInteractableLayers(LayerMask layers);