documentation

Tracking Events in Unity

Level: Intermediate

In Unity, you can listen to several events that are emitted by VisionLib to react to them.

List of available events

Event Parameters

Description

TrackingManager.OnTrackerInitializing Event which will be emitted once after calling the StartTracking function.
TrackingManager.OnTrackerInitialized Event which will be emitted after the tracking configuration was loaded.
VLWorkerBehaviour.OnTrackerRunning Event which will be emitted once after the tracking was stopped or paused and is now running again.
TrackingManager.OnTrackerPaused Event which will be emitted after the tracking was paused.
TrackingManager.OnTrackerStopped Event which will be emitted after the tracking was stopped or the initialization of the tracker has failed.
TrackingManager.OnTrackingStates TrackingState state Event with the current tracking state of all tracked objects. This event will be emitted for each tracking frame. See also Tracking States in Unity.
TrackingManager.OnPerformanceInfo PerformanceInfo state Event with the current tracking performance. This Event will be emitted for each tracking frame.
TrackingManager.OnIssueTriggered VLIssue issue Event which will be emitted if an Issue was triggered.

Using Unity Events in the Inspector

The VisionLib SDK for Unity provides two components that help to react on certain events by registering to them through the Inspector without the need to write a custom script:

  • The TrackerEventProvider component lets you react to OnTrackerInitialized and OnTrackerStopped
  • The TrackingStateProvider component lets you react to tracking state changes (Tracked, Tracking Critical, Tracking Lost) of the given object, see Tracking States in Unity

Register to Events in code

To react to VisionLib events in your own MonoBehaviour script, register to them like seen below:

using Visometry.VisionLib.SDK.Core;
...
void OnEnable()
{
TrackingManager.OnTrackerInitialized += HandleTrackingInitialized;
}
void OnDisable()
{
TrackingManager.OnTrackerInitialized -= HandleTrackingInitialized;
}
private void HandleTrackingInitialized()
{
// do something
}