The OptiTrack Unity3D Plugin allows you to stream real-time Rigid Body, Skeleton, and HMD tracking data from Motive into Unity. Using the streamed data, objects and characters in the scene can be animated. The plugin contents are distributed in unitypackage format, and you can simply load this file into Unity projects to import its contents. Once imported, included C# scripts can be used for instantiating a client origin and receiving the tracking data. This article focuses on how to set up and use the plugin.
Unity Version: 2017.2 / 2017.1 or above. (2020.3+ recommended)
Visual Studio 2019 or latest Visual C++ Redistributable
Notes on HMD Integration
The HTC VIVE, VIVE Pro, VIVE Pro 2, Valve Index, and HP Reverb HMDs can be integrated through the OptiTrack OpenVR Driver.
From Motive, the tracking data can be streamed in real-time either from a live capture (Live Mode) or recorded data (Edit Mode). The streaming settings are configured by modifying the Streaming Settings. NatNet streaming must enabled and the correct IP address must be set.
Streaming in Motive
Open the Streaming Settings in Motive and configure the settings below:
Enable - Turn on the Enable setting at the top of the NatNet section.
Local Interface - Choose the desired IP network address from this dropdown to stream data over.
Transmission Type - Typically you will want to set this to Unicast since it subscribes only to the data you wish to use and normally uses less network bandwidth. This is especially advised if streaming data over WiFi.
(Optional) If using Multicast, then enable/disable the desired data types. For tracking HMDs, disabling the Marker streaming is advised.
Additional Tips
In order to stream data from Edit mode, a capture recording must be playing back in Motive.
For best results, it is advised to run Motive and Unreal Engine separately on different computers, so that they are not competing for processing resources.
When streaming the data over a WiFi network, Unicast transmission must be used.
While in the Unity project, double-click on the plugin unitypackage file and import the plugin assets into the project. When the package has been successfully imported, the following contents will be available within the project:
Plugin Contents
In order to receive tracking data from a server application (e.g. Motive), a client object must be set up. The OptitrackStreamingClient.cs script can be attached to any object to stream data relative to that object. Typically, this script is attached to an empty object or loaded in using the "Client - OptiTrack" prefab object in the Assets/Optitrack/Prefabs
folder.
[Motive] In the Streaming Settings, configure the desired connection settings.
[Unity] Under the Prefabs folder, import the "Client - OptiTrack" prefab object into the scene, or attach OptitrackStreamingClient.cs script onto an empty object.
[Unity] In the streaming Client object, configure the connection settings to match the streaming settings in Motive.
Server Address - IP address of the PC that the server application (Motive) is running on.
Local Address - Local IP Address of the PC that the client application (Unity) is running on. (Typically, this looks similar to the Server Address except maybe the last digits.)
Connection Type - Must match Motive. Unicast is recommended.
[Unity] If you wish to receive tracking data from more than one server instances, you may create multiple objects with the client script attached.
Position Data in Unity
Although it is not strictly necessary, you may find it helpful to organize your tracked objects as children of the streaming Client object. This will allow you to adjust the position of the Client object to adjust the position of all streamed objects relative to the Client object.
[Unity] On an object that you wish to animate, attach the OpitrackRigidBody.cs script.
[Unity] In the Streaming Client entry, link the Client object in which the OptitrackStreamingClient.cs script is attached. By default, it searches for an existing client instance, but this must be specified when there are more than one streaming client objects.
[Unity] For the Rigid Body ID entry, input the streaming ID of corresponding Rigid Body asset in Motive. The streaming ID can be found, and changed, under the Rigid Body properties.
[Motive] Make sure Motive is tracking and streaming the data.
[Unity] Play the scene. The linked object will be animated according to the associated Rigid Body movement in Motive.
By integrating with Unity's animation system, Mecanim, the Unity3D plugin allows Motive to stream full body Skeleton data. The Skeleton tracking data from Motive is streamed out as hierarchical bone segment orientations, and this data is fed into the Unity's Mecanim system which allows animating characters with different proportions.
Note: At the time of writing, Mecanim does not support explicit goals for inverse kinematics end-effectors when using real-time retargeting. In addition, you may observe a difference in the overall scale of the position data between the retargeted skeletal animations and streamed Rigid Bodies. These two limitations may lead to inconsistencies with actors interacting with Rigid Body props, and will hopefully be addressed in a future version of the integration.
[Unity] On Unity characters, attach OptitrackSkeletonAnimator.cs script as one of its components.
[Unity] For the Streaming Client entry, link the Client object in which the OptitrackStreamingClient.cs script is attached. By default, it searches for an existing client instance, but this must be specified when there are more than one streaming client objects.
[Unity] Enter Skeleton Asset Name which is assigned in Motive
[Unity] For the Destination Avatar entry, link to the character's avatar component.
[Motive] Make sure Motive is tracking and streaming the data.
[Unity] Play the scene. When everything is set up properly, the linked avatar in Unity will be animated according to the streamed Skeleton in Motive. The position of the actor will be in its reference position as explained above.
[Unity] On the OptiTrack Streaming instance, enable the Draw Markers, "Draw Cameras", or "Draw Force Plates" setting(s).
[Motive] Make sure that marker streaming is enabled in Motive if you wish to visualize markers.
[Unity] Make sure the streaming setting is set up correctly, and play the scene.
[Unity] Each marker, camera, or force plate will be drawn in the scene, as shown in the screenshot below. (Note: Only markers will animate.)\
OptiTrack motion capture systems can be used to track head mounted displays (HMD) and integrate the tracking data into Unity for unique VR applications. For instructions on integrating HMD tracking data into Unreal Engine, please refer to the corresponding page Unity: HMD Setup.
Supported HMDs
At the time of writing, the following HMDs are supported:
HTC VIVE
HTC VIVE Pro
HTC VIVE Pro 2
Valve Index
HP Reverb
When setting up multiplayer games with wireless clients, it is more beneficial for each client to make direct connection to both the tracking-server (Motive) and the game-server, rather than rebroadcasting the streamed tracking data through the game-server. Then, any of the game related actions that interacts with the tracking data can be processed on the game-server, and this server can send out the corresponding updates to the wireless clients. This allows the wireless clients to only receive both the tracking data or updates without having to send back any information; in other words, minimizing the number of data transfers needed. If wireless clients are sending data there will be a minimum of two transfers on the wireless network, and each transfer of data through wireless network is at risk of latency or lost packets.
Folder | Content Description |
---|---|
Assets/OptiTrack
All of the Unity plugin contents are included in this folder.
Assets/OptiTrack/Scripts
This is the folder that you will mainly use. It contains plugin C# script components that can be imported into Unity objects for receiving streamed data.
Assets/OptiTrack/Plugins
This folder contains the plugin libraries and header files.
Assets/OptiTrack/Prefabs
This is the easiest place to get started. This folder contains premade objects for setting up a streaming client, tracking a Rigid Body, and retargeting a Skeleton.
Assets/OptiTrack/Scenes
This folder contains sample Unity scene that includes pre-configured client, Rigid Body, and Skeleton objects.
This page provides instructions on setting up the OptiTrack OpenVR driver for integrating OptiTrack system with Vive HMDs within SteamVR applications; including Unreal Engine and Unity.
For integrating Vive / Vive Pro / Valve Index HMDs, the OptiTrack OpenVR Driver must be used. This driver lets you track the head-mounted display (HMD) and the VR controllers using OptiTrack motion capture system and stream the tracking data from Motive directly into SteamVR. In other words, this will basically override the tracking from the lighthouse stations. The plugin ships as an installer package (MSI) which will set up the driver along with a utility tool for configuring client streaming settings. Once integrated, the streamed tracking data can be used in any application platform that utilizes SteamVR. For tracking of objects other than the HMDs, please read through the OptiTrack Unity Plugin page for details.
VIVE
VIVE Pro 1/2
Valve Index
HP Reverb G2
First of all, setup and optimize the motion capture volume as explained in the Getting Started guide or the Hardware Setup documentation. If you plan to install any obstacles (e.g. walls) within the capture volume, make sure they are non-reflective, and place and orient the cameras so that every corner is thoroughly captured by multiple cameras.
General Setup Steps
Attach the markers on the HMD
Create a Rigid Body asset
Calibrate the Pivot Point of the Rigid Body
Configure the Rigid Body settings in Motive
For the camera system to track the HMD, a set of markers must be attached to the HMD. You can either use the active markers (Active HMD clip or Active Tags) or the passive markers. Passive markers are retroreflective markers that reflect infrared light emitted from the IR LEDs on the camera. On the other hand, the active markers are LED markers that emit the IR light and has the intelligence to be uniquely identified.
In general, for most VR applications, using active markers is recommended for better tracking stability and ease of use. Active markers also have advantages over passive markers when tracking a large number of objects. For applications that are sensitive to the accuracy of the tracking data, using passive marker may have more benefits. To get more help with finding the best solution for your tracking application, please contact us.
When using the active markers, you can conveniently put a set of 8 markers onto the HMD by using the HMD Clip, or you can attach the markers from the Tag manually onto the HMD using adhesives and marker posts.
Active HMD Clip
Active HMD Clip is an HMD enclosure with a total of 8 active markers embedded for tracking. At the time of writing, there are active HMD clips for Vive Pro / Valve Index HMDs available on the webstore. The clips can be mounted easily by pushing it onto the HMD until the latches click, and you can detach it by gently lifting the three latches located at the top, left, and right side of the clip.
Once the clip has been mounted, next step is to import the provided Rigid Body asset into Motive and refine the definition to get the calibrated pivot point position and orientation, which will be explained on the next section.
Marker Types
You can either use the passive retro-reflective type markers or the active LED markers to track the HMD. Passive markers are retroreflective markers that reflect infrared light emitted from the IR LEDs on the camera. On the other hand, the active markers are LED markers that emit the IR light which gets uniquely identified in Motive. Either type of marker can be used to track HMDs. Using active marker is recommended especially for applications that involve tracking of multiple HMDs in the scene.
Marker Placement
Make sure the markers are attached securely and do not move. If the markers happen to move even slightly after a Rigid Body is defined, it will negatively affect the tracking and the Rigid Body definition may need to be updated.
Avoid placing multiple markers in close vicinity as they may overlap in the camera view in certain orientations.
Using marker posts to extend out the markers is recommended to improve marker visibility from more angles.
If you are using the active markers, there is an extra USB port on the HMD that you could draw the power from.
Please read through the Rigid Body Tracking page for additional information on the marker placement on a Rigid Body.
This feature can be used only with HMDs that have the OptiTrack Active HMD clips mounted.
For using OptiTrack system for VR applications, it is important that the pivot point of HMD Rigid Body gets placed at the appropriate location, which is at the root of the nose in between the eyes. When using the HMD clips, you can utilize the HMD creation tools in the Builder pane to have Motive estimate this spot and place the pivot point accordingly. It utilizes known marker configurations on the clip to precisely positions the pivot point and sets the desired orientation.
HMDs with passive markers can utilize the External Pivot Alignment tool to calibrate the pivot point.
First of all, make sure Motive is configured for tracking active markers.
Open the Builder pane under View tab and click Rigid Bodies.
Under the Type drop-down menu, select HMD. This will bring up the options for defining an HMD Rigid Body.
If the selected marker matches one of the Active clips, it will indicate which type of Active Clip is being used.
Under the Orientation drop-down menu, select the desired orientation of the HMD. The orientation used for streaming to Unity is +Z forward and Unreal Engine is +X forward, or you can also specify the expected orientation axis on the client plugin side.
Hold the HMD at the center of the tracking volume where all of the active markers are tracked well.
Select the 8 active markers in the 3D viewport.
Click Create. An HMD Rigid Body will be created from the selected markers and it will initiate the calibration process.
During calibration, slowly rotate the HMD to collect data samples in different orientations.
Once all necessary samples are collected, the calibrated HMD Rigid Body will be created.
This is supported only for Motive versions 2.1.2 or above. If you are using any other versions of Motive 2.1, please update the version to 2.1.2, or use a template to create the Rigid Body definition; instructions for which is provided in the following page: Using a Template File to Create Vive Pro Active Clip Rigid Body.
SteamVR Required: The VR driver streams tracking data through SteamVR. Please make sure SteamVR is installed on the computer before setting up the driver.
Download the OpenVR driver from the downloads page. Once downloaded, launch the installer and follow the prompts to set up the driver. On the last window, make sure to select Launch Configuration Utility before clicking Finish. This will open the Configuration options to setup your HMD with Motive.
You may receive a warning window prior to the installation wizard. To circumvent this, select More info and then Run Anyway.
Once the driver has been successfully installed, launch the configuration utility software (C:\Program Files\OptiTrack\OpenVR Driver\ConfigUtil). Using this tool, you can load and check existing configurations and make changes to the settings as needed. To import current settings, click Load and to save out the changes, click Save.
Please make sure you are running this tool with admin privileges; if not, it might not be able to modify the settings properly. If the configuration software detects a running instance of SteamVR through OpenVR, it will be indicated as Initialized at the very top as shown in the image. Please note that when the settings get modified while SteamVR is running, the SteamVR must be restarted to apply the changes.
First, configure the connection settings so that the driver listens to the Motive server where the tracking data is streamed from. The server address must match the address where Motive is streaming the data to, and the local address must match the IP address of the computer on the network where the driver is installed.
In the HMD section, enable the HMD and input the Rigid Body ID of the HMD. The Rigid Body ID must match the Streaming ID property of the HMD Rigid Body definition in Motive.
Save the configurations by clicking on Save. This will modify the set of configurations in the steamvr.settings file in the steam installation directory and they will override the HMD tracking with the tracking data from Motive. If you already had an instance of OpenVR or SteamVR running, restart the application to apply the changes.
Configuration File
The configuration tool basically imports and modifies the contents in the steamvr.settings file (C:\Program Files (x86)\Steam\config\steamvr.settings). When needed, the driver related settings can be changed directly from this file also, but it will be easier to configure the settings using the provided configuration tool.
Launch SteamVR. If the driver is successfully set up, you should see a tracker icon added to the right of the HMD icon and the HMD will now be using the motion capture system instead of the base stations. Here, please make sure all of the lighthouse base stations are powered off.
VIVE controllers are a Beta feature and may not work for every device. Support for this particular feature is limited.
Setting up the controller (optional)
When needed, the Vive controllers can be configured as well. To do so, open the configuration utility tool while SteamVR is running. At the top of the configuration tool, it should indicate OpenVR status as Initialized and the controllers must be showing up in SteamVR. Then, in the controller sections, enable the controllers, specify the override device using the drop-down menu, and input the corresponding streaming ID of the controller Rigid Bodies in Motive. Once everything has been configured, save the changes and restart SteamVR. When the override is configured properly, SteamVR will have an additional tracker icon per each enabled controller.
Now that the driver is set up, the HMD tracking will be overridden by tracking data from the mocap camera system, and you can integrate HMDs into the game engine through their own VR integration.
First, make sure the streaming settings are configured in Motive for streaming out the data. For more information on streaming in Motive please visit our Streaming page:
Broadcast Frame Data must be set to true.
Local interface must be set to the desired IP address to stream the tracking data from.
Streaming of Rigid Bodies must be set to True
For wireless streaming, use Unicast streaming type.
Once Motive is configured for streaming, launch SteamVR home to check the connection. If everything is setup correctly, you should be able to move around, or translate, within the scene freely. You may also need to check the ground plane to make sure it's well aligned.
If you experience any unexpected rotations in the view as you move your head, it could indicate that the HMD pivot point has not been calibrated properly. Please revisit the HMD Setup section and make sure the HMD Rigid Body pivot point is positioned and oriented at the expected pivot; which is at the root of nose with z-forward.
Once this has been set up, the motion capture system will be used to drive the HMD in SteamVR. In Unity, you should be able to setup development for SteamVR applications and use our system.
Starting from Unity version 2019 and above, official support for OpenVR in Unity has been deprecated. However, Valve made a plugin for the new Unity XR which can be used instead. Please follow the below steps to set up the Unity XR plugin and get the HMD working inside the Unity project:
OpenVR Unity XR plugin setup
1) Download the OpenVR Unity XR package found on the following Github page. 2) Download the OptiTrack OpenVR driver found on our website and configure the settings as described in the above section. 3) Open an Unity project 4) [Unity] Open the package manager from Window → Package manager. 5) [Unity] In the package manager, click on the "+" icon at the top and choose Add package from tarball. Then select the downloaded OpenVR Unity XR package.
6) [Unity] Check to make sure that the OpenVR XR plugin has been installed within your project.
7) [Unity] Now, follow the instructions on Unity's website to configure your project for XR development. Install the XR Plug-in manager which can be found under Edit → Project Setting → XR Plug-in Management.
8) [Unity] Enable the OpenVR Loader under the list of providers in the XR Plug-in Manager. If OpenVR Loader is not listed in there, make sure the plugin was installed properly from step 5) above.
9) [Unity] Once the plugin is configured, go to GameObject → XR → Add XR Rig.
10) Play the scene, and make sure the HMD is playing and tracking as well.
Please keep in mind that these steps are subject to change from Unity. You can find detailed instruction from the following page: https://docs.unity3d.com/Manual/configuring-project-for-xr.html
In Unity version 2018 and earlier, you can enable SteamVR by configuring the project setting. Please go to Edit → Project Settings → Player, open the XR Settings panel, and enable the Virtual Reality Supported property. You can also follow the instruction in the Unity Documentation:
This driver is designed for streaming of HMD and controller tracking data only. For streaming tracking data of other Rigid Body objects, you will need to use the corresponding plugins (Unreal Engine or Unity). In other words, the HMD tracking data will be streamed through the SteamVR using the driver you've installed, and all other tracking data will be streamed through the plugin.
Client Origin
When using the OpenVR driver along with the OptiTrack Unity Plugin for streaming of tracking data other than the HMD, such as Rigid Bodies and/or Skeletons, it is important that the OptiTrack Client Origin object is located at the global origin without any rotations. In other words, the position must be set to (0,0,0) and the rotation must be set to (0,0,0) on the client origin. This is important because the driver does not use the OptiTrack Unity Plugin but instead streams the HMD tracking data directly onto SteamVR through a separate channel.