Skip to content

Detector

GameObject-only detector with a pluggable detection strategy, filter chain, and reactive lifecycle.

Namespace: Jungle.Core Inherits: ControllableComponentMonoBehaviour Implements: IDetectorHost, IItemSource<GameObject>

Overview

Detector is the unified, domain-neutral way to find GameObjects in the scene. It combines:

  • A pluggable [IDetectionStrategy] (trigger volume, raycast, proxy, …) that decides how to discover candidates.
  • A chain of IObjectSelection steps that transform each raw candidate into 0..N tracked GameObjects. Steps narrow (filters), substitute (rewriters), or broaden (hierarchy walks, lookups) — compose them with Sequence to express patterns like "parents with a Point of Interest" or "children with a Rigidbody". Plain filters keep working — they're the cardinality-≤1 case.
  • Lifecycle processes that begin/end with detection edges (any-available, none-available) and on each add/remove.
  • UnityEvents for designer-friendly hooks on detection edges.

Detectors are pure read-only sources of GameObjects (IItemSource<GameObject>). They never mutate external containers as a side effect — use a DetectorToContainerRelay to mirror detection into a container.

For typed component resolution (e.g. "detect every AttachableObject in range"), combine a SmartX value in Dynamic mode with an IComponentLookupStrategy on the consumer side. The detector itself stays domain-neutral.

Selection vs filter semantics

A single raw detection (one trigger enter, one raycast hit) can produce more than one tracked GameObject when the selection chain includes an expansion step. Example: a raw collider hit + Sequence(HierarchyExpand{Parents}, HasComponentFilter{WeightedPoint}) yields every POI-bearing ancestor of the hit object. Each yielded GameObject ref-counts independently — onNewAvailable fires once per unique object, onNotAvailableAnymore fires when the raw hit eventually leaves range and its contribution to each is unwound.

Properties

Detection

Property Type Description
detectionStrategy IDetectionStrategy How this detector discovers candidates (triggers, raycasts, proxy, …).
selection List<IObjectSelection> Selection steps applied to each raw detection. Each step may filter, rewrite, or expand the candidate. Compose with Sequence.

Processes

Property Type Description
onAddedProcess IProcess Triggered each time an object is added to this source.
onRemovedProcess IProcess Triggered each time a previously added object is lost.
anyAvailableProcess IProcess Begun when transitioning from none → at least one available. Completed when all are lost.
noneAvailableProcess IProcess Begun when all detected objects have been lost. Completed when a new object is detected.

Events

Property Type Description
onNewAvailable UnityEvent<GameObject> Invoked when an object becomes available.
onNotAvailableAnymore UnityEvent<GameObject> Invoked when a previously available object is no longer valid.
onNoMoreAvailable UnityEvent Invoked when the source has no objects left.

Runtime State

Member Description
Available Iterable of currently-detected objects.
First / Last First / last entry in the available list.
LastAdded / LastRemoved Most recent add / remove.
IsDetecting True when at least one object is available.
DetectedCount Number of currently-detected objects.

Methods

Method Description
IgnoreUntilLost(GameObject) Marks an object as ignored until the strategy reports it has physically left detection range.
IgnoreAllCurrentlyAvailable() Marks every currently-available GameObject as ignored.
ReleaseIgnored(GameObject) Releases the ignore flag.
ReleaseAllIgnored() Releases all ignore flags.
ClearDetected() Clears every detected object and raises matching lost events.

See Also