ObjectDetectionConsumer
public class ObjectDetectionConsumer : Singleton<ObjectDetectionConsumer>
Namespace: AR51.Unity.SDK · Inherits: Singleton<ObjectDetectionConsumer> (MonoBehaviour) — access the live scene instance through ObjectDetectionConsumer.Instance.
Subscribes to the object-detection stream and spawns/updates GameObjects for detected markers and 6-DoF tracked objects. Each spawned GameObject carries a TrackedInstance component describing its current state. Positions are in Unity world space (meters), transformed through the configured Origin/anchor.
Unity positions, radii, and lengths are in meters (world space); rotations are Quaternion; angles in degrees. Several fields below carry ⚠️ flags where the source unit or behavior needs confirmation — preserved verbatim.
Properties
All Inspector configuration fields are public (set in the Inspector or before Start). Read-only state is exposed as get-only properties.
| Property | Type | Default | Description |
|---|---|---|---|
| Display toggles | |||
ShowMarkers | bool | true | show plain detection markers |
ShowObjects | bool | true | show 6-DoF tracked objects |
ShowSkeletonMarkers | bool | false | show skeleton joint markers |
ShowMarkerItems | bool | true | show prefab marker-items in place of markers |
| Prefabs & materials | |||
MarkerMaterial | Material | — | base material for spawned markers / default cubes |
Prefabs | GameObject[] | — | prefab pool for 6-DoF objects, matched by name to the server object Name |
MarkerItems | MarkerItem[] | — | per-marker-type prefab overrides |
| Marker sizing | |||
MarkerSize | float | 1 | global scale multiplier for markers (applied as MarkerSize * Radius) |
BasketballRadius | float | 0.12 | fixed radius (m) for markers whose type contains "ball" |
SkeletonMarkerSize | float | 0.05 | scale (m) for skeleton markers |
SkeletonMarkerColor | Color | Color.blue | color applied to skeleton markers |
| Non-max suppression | |||
EnableNMSWorkAround | bool | false | hide duplicate new markers near existing ones |
NMSThreshold | float | 0.01 | distance (m) under which a new marker is suppressed as a duplicate |
| Kalman filtering | |||
EnabledFiltering | bool | false | enable Kalman filtering of marker/object positions |
ProcessNoise | double | 2 | Kalman process-noise parameter |
MeasurementNoise | double | 0.005 | Kalman measurement-noise parameter |
FutureDeltaTime | double | 1.0/120.0 | prediction horizon (seconds) |
UseDiscreteWhiteNoise | bool | true | Kalman noise-model toggle |
UseAcceleration | bool | true | include an acceleration term in the filter model |
| Smoothing (6-DoF objects) | |||
SmoothRotationFactor | float | 0.2 | [0..1] slerp weight for object rotation smoothing |
SmoothPositionalFactor | float | 0.2 | [0..1] lerp weight for object position smoothing |
SmoothRotationAngleThreshold | float | 12 | [0..90] degrees; above this, rotation snaps instead of smoothing |
SmoothPositionalThreshold | float | 0.03 | distance (m) above which position snaps instead of smoothing |
| Placement & misc | |||
ModelLayer | int | 0 | Unity layer assigned to spawned objects |
Origin | Transform | — | origin transform; spawned content aligns to its local-to-world |
IsDebug | bool | false | debug flag |
| Read-only state | |||
ModelLayerName | string | — | name of ModelLayer (get-only) |
CameraIds | List<string> | — | IDs of cameras contributing to the latest frame; refreshed each frame (get-only) |
TrackedInstances | IEnumerable<TrackedInstance> | — | all currently tracked instances (markers + objects) (get-only) |
TrackedMarkers | IEnumerable<TrackedInstance> | — | currently tracked markers only (get-only) |
TrackedObjects | IEnumerable<TrackedInstance> | — | currently tracked 6-DoF objects only (get-only) |
Method summary
Instance
| Method | Returns | |
|---|---|---|
OnObjectDetected | void | stream callback |
AddTrackedObject | void | public |
RemoveTrackedObject | void | public |
ResetModels | void | public |
→ Full descriptions in Method details below.
Events
Standard C# event delegates — subscribe with +=.
| Event | Signature | Fires when |
|---|---|---|
OnObjectDetectionReceived | EventHandler<ObjectDetectionReply> | once per received detection frame, at the start of processing, before GameObjects are updated |
The ObjectDetectionReply argument (⚠️ declared elsewhere — AR51.GRPC.CVS transport type) carries the frame's markers, items, cameras, and capture time. Use it to observe raw detection frames as they arrive.
Method details
OnObjectDetected
public void OnObjectDetected(ObjectDetectionReply e);
Processes one detection frame: fires OnObjectDetectionReceived, then creates / updates / positions the marker and object GameObjects. Normally invoked internally from the stream; call it to feed a frame manually (e.g. playback). ⚠️ ObjectDetectionReply is a transport type declared elsewhere.
AddTrackedObject
public void AddTrackedObject(string name, TrackedInstance[] markers);
Registers a new trackable rigid object on the server, defined by the given marker instances (their color types and positions, recentered to their average). No-op with an error log if the object-detection client is unavailable.
// Define a rigid object from the currently-tracked markers
var consumer = ObjectDetectionConsumer.Instance;
consumer.AddTrackedObject("Racket", consumer.TrackedMarkers.ToArray());
RemoveTrackedObject
public void RemoveTrackedObject(string name);
Unregisters a previously added tracked object by name.
AddTrackedObjectResetModels
public void ResetModels();
Destroys all spawned marker / object GameObjects and clears internal tracking. Call to flush stale visuals (e.g. on scene reset or anchor change).
Inspector configuration
Drop the component on a GameObject (or reach it via ObjectDetectionConsumer.Instance). The fields under Properties are the Inspector knobs:
- Display toggles (
ShowMarkers,ShowObjects,ShowSkeletonMarkers,ShowMarkerItems) gate which detection categories are rendered. Prefabsis the pool for 6-DoF objects, matched by name to the server objectName;MarkerItemsoverride individual marker types with custom prefabs (seeMarkerItem).Originanchors all spawned content — set it to the transform that represents your tracking space.- Filtering / smoothing fields tune the Kalman filter and per-object position/rotation smoothing.
InstanceType
enumpublic enum InstanceType { Marker, Object }
Namespace: AR51.Unity.SDK. Nested in ObjectDetectionConsumer. Classifies a TrackedInstance.
| Value | Meaning |
|---|---|
Marker | a simple marker — sphere / 3-DoF point |
Object | a full 6-DoF tracked object |
MarkerItem
class · [Serializable][Serializable]
public class MarkerItem
Namespace: AR51.Unity.SDK. Nested in ObjectDetectionConsumer. Maps a marker type string to a prefab to spawn in place of the default marker. Edit entries in the Inspector via the MarkerItems array.
| Field | Type | Default | Description |
|---|---|---|---|
MarkerType | string | — | the marker type / color label this entry matches |
Prefab | GameObject | — | prefab instantiated and tracked at the marker's position |
Enabled | bool | true | whether this marker-item is shown |
TrackedMarkerExtensions
static classpublic static class TrackedMarkerExtensions
Namespace: AR51.Unity.SDK. Static (non-MonoBehaviour) utility extension methods on TrackedMarker for interpreting marker IDs.
IsSkeletonMarker
public static bool IsSkeletonMarker(this TrackedMarker marker);
Tests whether the marker represents a skeleton joint (its Id contains "Skeleton"), letting callers distinguish skeleton-driven markers from free-standing detection markers.
true if the marker is a skeleton joint markerTrySkeletonMarkerInfo
public static bool TrySkeletonMarkerInfo(this TrackedMarker marker, out string skeletonId, out string jointName);
Attempts to parse a skeleton marker's Id into a skeleton identifier and joint name. Returns false (with null outs) for non-skeleton markers. On success, skeletonId is normalized to a "Skeleton:Classic..." form and jointName is the joint label. ⚠️ needs confirmation: the exact skeletonId / jointName string formats depend on the server's marker-ID naming scheme.
null otherwisenull otherwisetrue if the marker is a skeleton marker and was parsedSee also
TrackedInstance— the per-instance data model attached to each spawned marker / object GameObjectObjectTransformConsumer— the parallel consumer for generic object transforms (position / rotation / scale)ObjectTransform— a single object's pose fed toObjectTransformConsumerXRHeadsetTracker— streams XR-device transforms intoObjectTransformConsumerServiceManager— the connection entry-point that must be running before detections arrive- Class index — all Unity SDK types