> For the complete documentation index, see [llms.txt](https://help.imotions.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://help.imotions.com/lab/study-setup-and-design/virtual-reality/varjo/setting-up-the-imotions-unity-package-for-varjo-headsets.md).

# Setting up the iMotions-Unity package for Varjo headsets

Use the iMotions-Unity package 2.1 for Varjo headsets to stream eye tracking, gaze and collision events into iMotions Lab, with optional hand tracking.

Virtual reality environments keep evolving and at iMotions we strive to bring those features to your multimodal experiments. With that in mind, we have now released a new Unity-iMotions package which upgrades and enhances the use of Varjo headsets with Unity environments in iMotions. The purpose of this article is to cover what the new features are and how you should go about designing your iMotions-compatible Unity environment. Note that this article will not cover how to configure your Varjo headset - that information is available within these articles.

**What is the purpose of this package?**

Unity, Varjo and iMotions are three separate systems that somehow need to be linked together. Our package enables API connections between Varjo, Unity and iMotions, such that all of your eye tracking data will be logged in iMotions. You simply have to “enable event reception” under the Global Settings/API/Event Receiving headline. Make sure that “Use TCP” should ***not*** be enabled. You are now all set!

**Who should use this package?**

* Anyone using Varjo VR headsets
  * Regardless of which Varjo VR headset you have, you will be working with this package in Unity.
  * If you have a VR3 or an XR3 you can enable hand-tracking. We have pin-pointed specific steps/paragraphs that are relevant for enabling hand-tracking.
  * Regardless of which Varjo VR headset you use, this package sends an API stream of gaze-trigger events into iMotions which mark when the gaze focuses on an object in the environment.

**What updates are included in the new iMotions-Unity package?**

* You can use [High Definition Render Pipelines (HDRP) Unity environments.](https://unity.com/srp/High-Definition-Render-Pipeline)
* You can integrate with the Varjo Aero headset.
* The package now includes an established stable version of Unity (which will be updated as needed) and the Varjo plug-in for Unity. This eliminates the need for manually downloading the correct versions of Unity.
* You can now play “fake eye gaze data”, which enables easier Unity design development and testing in iMotions without having to wear the headset.
* You can track your hands, and interact with the virtual environment.
* Collisions between the virtual environment and your hands, eyes, or controllers are sent to iMotions via an API.

One note to consider before you proceed: HDRP 3D environments are very demanding on the computer’s processor and it is critical that you make sure your computer [can handle the requirements](https://support.varjo.com/hc/en-us/get-started-with-varjo-headsets#system-requirements). We always recommend that you consult an iMotions team member prior to purchasing a dedicated VR computer.

**How do you design a Unity environment with the new package?**

* Before you begin, find the latest package here: [iMotions Varjo Integration v2.1.6](https://github.com/imotions/iMotions-UnityPlugin/tree/varjo). You install it in Unity straight from GitHub (see *Step 1*), which needs [Git](https://git-scm.com/downloads) installed on the computer.
* Make sure you have Unity installed. The package works with Unity 2021.3, 2022.3 and Unity 6 (tested up to 6000.6), and needs Varjo Base 4.6 or newer. For Unity 2020.3, use [iMotions Varjo Integration v2.1.5](https://github.com/imotions/iMotions-UnityPlugin/tree/varjo-2.1.5). You can download Unity here: <https://unity.com/releases/editor/archive>
* If you want to do hand tracking, [download the LeapMotion plug-in through this link](https://github.com/varjocom/XR3-VR3-UnityModules). Download as a zip file (under “Code”) and extract all. The next update to the iMotions-Unity package will include a prepackaged LeapMotion plug-in so you will be able to skip this step.
* For ease, we recommend using a predetermined layout developed by us. This will make it easier for you to follow the step by step guide below. You can download the layout here and follow the directions:

*Step 1:* Open Unity and create a new 3D HDRP environment. Click on Packages and then click on the little plus sign next to it. Select “Add package from git URL” (“Install package from git URL” in Unity 6), paste `https://github.com/imotions/iMotions-UnityPlugin.git#varjo` and click “Add” (“Install” in Unity 6). For v2.1.5, paste `https://github.com/imotions/iMotions-UnityPlugin.git#varjo-2.1.5` instead. Upon importing the package, it will automatically install three “custom” packages including the Varjo package. Under "Custom" you will see three packages:

1. 3SL: iMotions Integration Core
2. 3SL: iMotions Varjo Integration
3. Varjo XR Plugin

Under the Varjo XR Plugin, click on "samples" and then import HDRP samples.

![3SL\_folder\_package.png](https://286068319-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNLNBWkNpljDaAj5rQtNa%2Fuploads%2Fgit-blob-909b28bb1ca6526285c62e4942aee64cd8a5b486%2F3478660085_3sl_folder_package.webp?alt=media)

![Varjo\_XR\_Plugin\_HDRP\_sample\_-\_importing.png](https://286068319-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNLNBWkNpljDaAj5rQtNa%2Fuploads%2Fgit-blob-4db7db65c991bb71764eb348e1db37d00db3d3a9%2F97a5cec211_varjo_xr_plugin_hdrp_sample_-_importing.webp?alt=media)

*Step 2:* Click on “Project Settings” and enable Varjo in the XR plug-in Management tab. Check out the settings provided in 3SL iMotions Varjo integration to switch the specific device you are using for your VR recordings (note: the only headset that supports hand-tracking properly is VR3). You will notice the ability to alter the “Gaze Output Frequency”. By default, this is set to ‘maximum supported’, which reflects the sampling rate of your VR headset. In some cases, it can be beneficial to reduce the sampling rate in order to increase the performance of the computer system.

![Project\_settings\_XR\_plug\_in\_-\_enabling\_Varjo.png](https://286068319-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNLNBWkNpljDaAj5rQtNa%2Fuploads%2Fgit-blob-aee3d4112d5be740d5b0dc0c0394bc5bf97f60a4%2F73556ba50c_project_settings_xr_plug_in_-_enabling_varjo.webp?alt=media)

![iMotions\_Varjo\_integration\_Project\_Settings.png](https://286068319-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNLNBWkNpljDaAj5rQtNa%2Fuploads%2Fgit-blob-abe496f44f2f3fe9099991c1aac17f6215f63987%2F90ea968666_imotions_varjo_integration_project_settings.webp?alt=media)

*Step 3*: This step is only required if you are doing hand tracking (using the VR3 headset): Now go to your Unity study folder, and copy/paste the LeapMotion Assets/Plug-Ins folder into your Unity file’s Assets/Plug-ins folder. This action will automatically import the LeapMotion package into your Unity Study when you return to the Unity interface.

![Leap\_motion\_folder.png](https://286068319-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNLNBWkNpljDaAj5rQtNa%2Fuploads%2Fgit-blob-d2a118ce25f597c20e5cd0e7708fa33f94614acc%2F1fa6069369_leap_motion_folder.webp?alt=media) ![Leap\_Motion\_copied\_into\_Assets\_folder.png](https://286068319-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNLNBWkNpljDaAj5rQtNa%2Fuploads%2Fgit-blob-e9476c1ddd873b42af5a8e3363a4378db742b17c%2F2b73a2b894_leap_motion_copied_into_assets_folder.png?alt=media)

*Step 4*: Go to Package Manager in Unity, click 3SL: iMotions Varjo Integration and go to “currently installed” to retrieve the package samples:

* If you are **using the built in rendering system** (not HDRP), import the Built-In render pipeline sample study (first sample study)
* If you are **using hand tracking with built-in rendering,** import the hand tracking Samples (Built-in render pipeline) together with the Built-In render pipeline sample study (first and second sample study)
* If you are **using HDRP resolution** for your game, import the HDRP sample study (third sample study)
* If you are using **hand tracking with HDRP resolution**, import the hand tracking sample study (HDRP) together with the HDRP sample study (third and fourth sample study)

After you import the relevant study, it/they will populate your assets under the Project tab.

![3SL\_iMotions\_Varjo\_integration\_-\_import\_samples.png](https://286068319-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNLNBWkNpljDaAj5rQtNa%2Fuploads%2Fgit-blob-f8ca4a6ea35c509f0465330a482c043fd94eef2e%2F65b7415f8b_3sl_imotions_varjo_integration_-_import_samples.webp?alt=media)

*Step 5*: Open “samples” under "Assets", in the Project, and continue to open 2.1.1. Then open HDRP samples, and choose one of the HDRP examples by double clicking (Head Only or Controllers). Now go to the Hierarchy and click on "Varjo+iMotions….". Click on "Varjo Gaze Server" and click on the Inspector tab. Set the local address and port you want to use (only necessary to change if using different than default port; default port is 4050 and target port is always 8089).

Note: you may experience a pop up window asking you to save changes - if that happens, press save and proceed with step 6.

![HDRP\_sample\_2.1.1.png](https://286068319-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNLNBWkNpljDaAj5rQtNa%2Fuploads%2Fgit-blob-052a8994195febe3b340c6204714561c28a708bc%2F781f2bba0a_hdrp_sample_2.1.1.webp?alt=media)

![Varjo\_Gaze\_server\_-\_port\_info.png](https://286068319-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNLNBWkNpljDaAj5rQtNa%2Fuploads%2Fgit-blob-2ec4c5975af308a3a4a359d910d0ee4a749eaa30%2F5d364128f7_varjo_gaze_server_-_port_info.webp?alt=media)

*Step 6*: Go to project settings and click on “Player” and change "Active Input Handling" from "Input System Package (New)" to "Both". You may only see 4 lines of text, in that case, open the one called “Other Settings”. You will find "Active Input Handling" under the heading "Configuration", by scrolling down around two thirds of the way. Click apply then Unity will restart. Still under "Player", open "Resolution and Presentation" and check "Run In Background". Without it, Unity pauses when its window loses focus, for example when you click on iMotions, and iMotions stops receiving gaze data (the eye tracker shows 0 Hz). Build your study by clicking “Build Settings” (next to Package Manager) and click “Build”. You will now see your study in the folder you decided to save it in. Open Unity study and run it (the study has to be on a separate monitor as it cannot minimize).

![Player\_settings\_active\_input\_handling.png](https://286068319-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNLNBWkNpljDaAj5rQtNa%2Fuploads%2Fgit-blob-9b7e9f1dcddb2608ef35fa7b3727c3c7e4839091%2F47cd5294a1_player_settings_active_input_handling.webp?alt=media)

*Step 7*: Open Varjo Base and turn on your controllers. Open Analytics tab, and calibrate and ensure all settings are accurate

*Step 8*: Go to iMotions, click on "Create new study", then "Sensors". Check "Eye tracking", then select "Varjo VR" and "External Events API". Add a screen recording stimulus. Then go to "Global Settings", then the eye tracking tab, then select the proper eye tracking headset and then click "Test Connection". If you have issues establishing a connection to the VR headset try recalibrating inside the headset and reconnect.

Within the "Global Settings" window navigate to the API tab, and enable event reception. Note that this port has to match with your target port in Unity (do not check TCP, as we are using UDP). Add a respondent, and start recording. Calibration can be started by clicking on F1 on keyboard or by following the steps in the VR environment. As you record, you can see where the gaze is in the sensor preview in iMotions, and you can see live the gaze data events that are logged in Unity in the Unity interface that are then pushed into iMotions (note that if you have Unity editor open when also running your Unity environment the Unity editor will hold the 4050 port. In that case, save your Unity environment build with another target port (e.g. 4051, 5052)).

![The API tab of Global Settings with Enable event reception selected and its port](https://286068319-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNLNBWkNpljDaAj5rQtNa%2Fuploads%2Fgit-blob-22b774c63facbb2059b600b4e832977622e78d41%2Flab_global-settings_api_event-reception.png?alt=media)

*Step 9:* You are now ready to start a recording. After you have recorded your data, you can open the replay and visualize the gaze and hand tracking collisions with the objects in the environment. Click on "Live Markers", then "API events", and select whichever events you are interested in. These collision events are automatically streamed into iMotions via the API. You can use these event markers to create automated annotations for your respondents to streamline your data segmentation process for the objects tracked by the eyes, and the objects which the hands interacted with (note these events are referred to as ‘collisions’ in Unity). You may not want to send gaze data from every object your eyes interact/collide with. In that case, only add gaze targets to the objects you want to have information sent from. If you want to vary which objects you get information from, you should organize your objects in separate layers (for example 2 different layers with different objects in each) that you can select between by going to the "Inspector" tab, selecting "XRRig", then "Camera Offset" and then "\[Varjo PoV Camera]". Scroll down to "Varjo Gaze Trigger Event Source" and deselect ‘Everything’ in the "Gaze Trigger Layer Mask", and instead click on the layer you want gaze events from.

**How do you add hand tracking?**

If you want to do hand tracking go to the Unity editor, go to Package Manager. Under “Custom” go to "3SL: Varjo-iMotions Integration", click on "Samples" and choose "Hand tracking samples (HDRP)". Note that the process is the same regardless of whether you are using the Built-In render pipeline or the HDRP pipeline. Just make sure you have the correct sample studies downloaded. It will now populate your "Project" menu. Open XRRig under \[Varjo + iMotions (XRRig + hand Tracking)] in "Hierarchy", click “AttachmentHands". Make sure you are in the "Inspector" tab, and decide which point on the hand should be the trigger for collisions. It is by default set to the fingertip of the index finger - if you need to change it to another (or more) location(s) on the hand, we recommend that you reach out to us.

![Hantrackign\_Samples.png](https://286068319-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNLNBWkNpljDaAj5rQtNa%2Fuploads%2Fgit-blob-534cf591bafe51b7952745b51ced25674d985cfe%2F43d7ecf988_hantrackign_samples.webp?alt=media) ![AttachmentHands.png](https://286068319-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNLNBWkNpljDaAj5rQtNa%2Fuploads%2Fgit-blob-7792f1dfc9d65a807cd4fe5ec76ce6b750e7498c%2Fd6a129e54c_attachmenthands.webp?alt=media)

![Hantrackign\_Samples.png](https://286068319-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNLNBWkNpljDaAj5rQtNa%2Fuploads%2Fgit-blob-534cf591bafe51b7952745b51ced25674d985cfe%2F43d7ecf988_hantrackign_samples.webp?alt=media) ![Select\_han\_tracking\_HDRP\_-\_see\_ahnds.png](https://286068319-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNLNBWkNpljDaAj5rQtNa%2Fuploads%2Fgit-blob-b253a1d4e25c531624ea338676b036386ab9f6a6%2Ffc61947aeb_select_han_tracking_hdrp_-_see_ahnds.webp?alt=media)

Now you simply build your study again and follow the steps to play it in Varjo Base and connect to iMotions.

**How do you enable Fake Eye Gaze data collection?**

Sometimes connection issues can happen. To make it easier to troubleshoot any problems that might occur, it's possible to produce fake eye gaze data that doesn't require the use of the headset.

Click "Gaze Data Replay" under "HDRP Example iMotions-Varjo" in the "Hierarchy". Navigate to the Inspector. Check "Gaze Data Replay": fake eye gaze data will now be generated. You will now be able to see a gaze point in iMotions without wearing the headset. Note that the fake eye gaze data will take priority over "real" data and it is therefore critical that you uncheck this box when you collect experimental data. To simply check if the connection works between the Unity environment and iMotions with the fake eye gaze data, you can click on the play button in the Unity Editor (where you are creating your study) and it will now automatically start generating eye gaze data that will be picked up by iMotions.

![Fake\_Eye\_GAze\_data.png](https://286068319-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNLNBWkNpljDaAj5rQtNa%2Fuploads%2Fgit-blob-9ad5aa69b55cfe2fb175899e9efcebd1e91f033a%2F354e4b92c3_fake_eye_gaze_data.webp?alt=media)

**How do you add elements to the prepackaged sample environments?**

If you want to add your own collision and gaze triggers go into the editor and open up your sample study. Choose "Default Scene Assets" in the "Hierarchy". Go to the top bar, click “GameObject”, then "3D Object", and choose whichever object you want to add. If you want a customized object, select "Create Empty" and add your own components. Choose the origin of the new object, i.e. where it should be located. Add one or both components: "Varjo Gaze Trigger" and / or "Collision Trigger". Change the trigger name if needed (this is what you will see it referred to in iMotions). Ensure that “Is Trigger” in the box collider is unchecked (unless you want the object to be a trigger on its own). Move the new object into the line of the other objects, save, and then build your project. When you record and replay your recording in iMotions you will see the object populate the API events if you interacted with it.

![Add\_Elements.png](https://286068319-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNLNBWkNpljDaAj5rQtNa%2Fuploads%2Fgit-blob-1d327a6bf43211aa883f9946c5d0dbad22186ebb%2Fd066218817_add_elements.webp?alt=media)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://help.imotions.com/lab/study-setup-and-design/virtual-reality/varjo/setting-up-the-imotions-unity-package-for-varjo-headsets.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
