# MRTK

MRTK works great for UI and remote interactions. You can get the best of physically contrained UI and remote interaction with by using MRTK+HPTK.

However, MRTK has some particularities that you have to know in order to make it work properly:

* MRTK uses **Standard rendering pipeline**. HPTK comes out-of-the-box to use URP.
* MRTK uses **collision layers** to detect ray targets that may interfere with our collider-full hands.
* MRTK **instantiates the rig on run-time** according to the platform but HPTK singleton needs references to the camera and the tracking space origin.

## How to use MRTK + HPTK?

{% hint style="info" %}
**For new scenes,** add the **DefaultSetup** prefab that fits your target platform. If the scene does not contain any avatar, add the **DefaultAvatar** prefab that fits your render pipeline.&#x20;

**More details** about initial setup in [Setup](https://jorge-jgnz94.gitbook.io/hptk/master/setup) section.
{% endhint %}

### 1. Obtain MRTK

**MRTK +2.5** can be managed using the **Unity Package Manager (UPM)**. Follow this [documentation](https://docs.microsoft.com/es-es/windows/mixed-reality/mrtk-unity/configuration/usingupm) to install Mixed Reality features using the UPM.

If you're new to MRTK or Mixed Reality development in Unity, take a look to this [guide](https://docs.microsoft.com/en-us/windows/mixed-reality/develop/unity/unity-development-overview?tabs=mrtk%2Carr%2Chl2). This guide is the recommended starting point for MRTK, specifically created to walk you through the installation, core concepts, and usage of MRTK in Unity.

For educational purposes, [MRTK-Quest-Sample](https://github.com/provencher/MRTK-Quest-Sample) is a ready-to-go Unity project made by [provencher](https://github.com/provencher) that uses MRTK and Oculus Quest hand tracking.

### 2. Configure MRTK

Add **MicrosoftRealityToolkit** singleton to your scene.

Open the **MRTK Project Configurator** window (Mixed Reality Toolkit > Utilities > Configure Unity Project). Then **apply the recommended configuration**.

![](https://2698598769-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MYpeL-Cll-FXMj9b3XC%2F-MZ0DRIF-2VFwpZYizkE%2F-MZ0FNpKb3TZb5lISf4i%2Fimage.png?alt=media\&token=082a5746-0f5e-4330-a086-0630b1999ae1)

#### 2.1. Integrate Oculus-MRTK (Quest)

From Unity Package Manager, install the **Oculus XR Plugin** package.

**Integrate** Oculus Integration Unity modules from *Mixed Reality Toolkit > Utilities > Oculus > Integrate Oculus Integration Unity Modules*.

![](https://2698598769-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MYpeL-Cll-FXMj9b3XC%2F-MZ0DRIF-2VFwpZYizkE%2F-MZ0HKQAPPtKjBAn34Q2%2Fintegrate-oculus-mrtk.PNG?alt=media\&token=4f013eb9-8cd2-428b-b46e-4a899837c999)

### 3. Collision layers

Configure **layer collision matrix** in ProjectSettings/Physic&#x73;**:**

1. Create new layer called ***HPTK***.
2. Make ***HPTK*** layer to **ignore&#x20;*****Default*****&#x20;and&#x20;*****UI*****&#x20;layers**.

![](https://2698598769-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MYpeL-Cll-FXMj9b3XC%2F-MZ0DRIF-2VFwpZYizkE%2F-MZ0aLtfaN4Qj2C3vAgK%2Flayers.PNG?alt=media\&token=ac72f018-30d1-42fe-8698-98a59d361a92)

**Use the new collision layer.** In HPTK singleton, set `HPTK.applyThisLayerToChildren = HPTK`

On Start, HPTK will apply that layer to all its children as HPTK singleton is the root object that encapsulates the GameObjects related with HPTK, including the avatar representations.

### 4. Switch to StandardRP

If you are using the **DefaultAvatar.URP** prefab, replace it by the **DefaultAvatar.Standard** prefab variant.

{% hint style="info" %}
If DefaultAvatar.URP is part of another prefab, **unpack** its parent prefab first.
{% endhint %}

### 5. Remove references to camera and tracking spaces (Quest)

**Remove** any existing instance of **OVRCameraRig** as MRTK will instantiate it on start.

In the **HPTK singleton** set:

* `HPTK.trackedCamera = NULL`
* `HPTK.trackingSpace = NULL`

For each **OVRSkeletonTracker** set:

* `OVRSkeletonTracker.ovrHand = NULL`
* `OVRSkeletonTracker.ovrSkeleton = NULL`

When these values are missing, **each OVRSkeletonTracker will search for those values** each frame until finding them. They will find it once MRTK instantiates the OVRCameraRig.

### 6. Import HPTK+MRTK Integration Package

Open the **Integration Manager,** click on **MRTK** and import the built-in integration package.

![](https://2698598769-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MYpeL-Cll-FXMj9b3XC%2F-MZawcQtnL70TJejsCFU%2F-MZbEtUziL4LX3zjE9jQ%2Fmrtk-gif.gif?alt=media\&token=1dba9f21-8c70-4ad8-8e35-ec089738f7c4)

### 7. Import MRTK-Quest Integration Package (Quest)

Open the **Integration Manager,** click on '**MRTK Quest'** and import the built-in integration package.

This package contains a **demo scene** with MRTK+HPTK working for Oculus Quest.

MRTK Quest integration package has **dependencies with the Oculus integration package**. If Oculus integration package is not imported in your project, then open Integration Manager, click on Oculus and import the package.

### 8. Set the configuration profile

In the Mixed Reality Toolkit singleton, set the profile **MRTK-HPTK-ConfigurationProfile**.

![](https://2698598769-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MYpeL-Cll-FXMj9b3XC%2F-MZ0DRIF-2VFwpZYizkE%2F-MZ0JCzhb3tIvNdwZQRr%2Fmrtk-hptk-profile.PNG?alt=media\&token=7499515d-7795-4b9f-ab04-8092146f0ef5)

### 9. Add an interactive object

In `Assets/HPTK/Integrations/MRTK/Prefabs/Interactables` you will find some **example objects.**

These objects exemplify how MRTK remote interactions can be combined with touchable objects and physics-based near interactions.

These objects follow a **pattern**:

* **Root object:**
  * Uses the **Default layer.**
  * The MRTK-related components are attached to it.
  * Has a BoxCollider component that defines its boundaries.
* **Child object:**
  * Uses the **HPTK layer** (and its child objects).
  * Contains the Colliders that defines the touchable surface.
