Gaze tracking data with MRTK3 -Hololens2

Copper Contributor

Hi,
I am trying, in Unity, to export Eye gaze data, (preferably as coordinates relative to a 2D plane placed in front of the user).
The initial and main problem though is that I don’t know how to access said data through Unity.
I have read that I should first of all import

using Microsoft.MixedReality.Toolkit;
using Microsoft.MixedReality.Toolkit.Input;

Correct?

However, it gives me an error in the second line of code:

Error CS0234 The type or namespace name ‘Input’ does not exist in the namespace ‘Microsoft.MixedReality.Toolkit’ (are you missing an assembly reference?).

I initialized the project with MixedRealityFeatureTool, already importing the MRTK3 libraries (+XRplugin).

Are there any solutions to get the gaze data directly from Unity?

Any other ways?
Thank you!

1 Reply

 

To access eye gaze data in Unity using the Microsoft Mixed Reality Toolkit (MRTK), you need to use the EyeTracking namespace, not Input. The error you are encountering indicates that the Input namespace does not contain the necessary types for eye gaze tracking.

Here's an example of how you can access eye gaze data in Unity using MRTK:

 

csharpCopy code
using Microsoft.MixedReality.Toolkit; using Microsoft.MixedReality.Toolkit.Input; public class GazeTrackingExample : MonoBehaviour { private void Start() { // Check if eye tracking is supported if (CoreServices.InputSystem?.EyeGazeProvider != null) { // Subscribe to the eye gaze update event CoreServices.InputSystem.EyeGazeProvider.OnUpdated += OnEyeGazeUpdated; } else { Debug.LogWarning("Eye tracking is not supported or not available in this configuration."); } } private void OnEyeGazeUpdated( EyeTrackingEventData eventData) { // Access eye gaze data Vector3 gazePosition = eventData.HeadGazeData.GazeOrigin; Vector3 gazeDirection = eventData.HeadGazeData.GazeDirection; // Use gaze data as needed Debug.Log($"Gaze Position: {gazePosition}, Gaze Direction: {gazeDirection}"); } }
 

In this example, we subscribe to the OnUpdated event of the EyeGazeProvider to receive updates on the eye gaze data. The OnEyeGazeUpdated method is called whenever the eye gaze data is updated, and you can access the gaze position and direction from the EyeTrackingEventData.

Make sure that you have the necessary MRTK packages installed, and that your project is configured to use MRTK for eye tracking.

Click here: benny beach buggy racing