# Developing for NSDK on XR Headsets Source: https://www.nianticspatial.com/docs/nsdk/how-to/unity/headset_development/ Working with NSDK on XR headsets is, in many ways, the same as developing an AR experience for mobile devices. Due to hardware differences between XR headsets and a standard smartphone, some tasks must be done differently. In this How-To, you will learn about the differences and how to address them in your Unity project. ## Prerequisites 1. You must complete the [setup](https://www.nianticspatial.com/docs/setup/#install-the-niantic-sdk-packages) process for your supported XR headset before using this How-To. 2. You will need to authenticate your Unity project with Niantic Spatial Identity for the VPS section of this How-To. See the [Create Account page](https://www.nianticspatial.com/docs/create_account/) for more information. 3. Scripts in this How-To use elements from the `ARLocationManager` API. If you need a refresher, see [How to Use Location AR with Code](https://www.nianticspatial.com/docs/nsdk/vps/location_ar_code/). ## Playback By playing through pre-recorded footage in the Unity editor, NSDK's Playback system is able to simulate AR applications on a supported XR headset in the same way as it does on mobile devices. To use playback in the Unity Editor, you must enable **Niantic Spatial Development Kit for Unity Editor** as a plugin provider in **XR Plug-in Management** for Windows, Mac, Linux settings. (image: Enable Niantic Spatial Development Kit for Unity Editor) #### Meta Quest 3 > **Caution:** > > **Warning!** > > In the Unity Editor, the visualization of object detection results may not be in the correct orientation. This is a visual issue as object detection works as expected on-device. 1. Follow the instructions in [Using the API to Record Datasets](https://www.nianticspatial.com/docs/nsdk/playback/create_playback_dataset/#using-the-api-to-record-datasets) to record your playback dataset. **Note:** You must record in **landscape** to use the recording on the Meta Quest 3. 2. In Unity, open the **NSDK** top menu, then select **Settings**. In the **Playback** section, enter the path to your recording in the **Dataset Path** field. 3. Set up your XR scene with any necessary scripts and components, then press Play in the Editor to run the Unity scene using your recording. ## Spoofing Locations Because most XR headsets do not have GPS hardware, you may want to spoof a location if you're using NSDK's location-based features. Note that VPS no longer requires GPS coordinates when localizing. To spoof a location, you have two options: - NSDK Settings UI; or - Scripting via `RuntimeNsdkSettings.ActiveSettings` The UI is handy for quicker iteration while the scripting functionality is useful for situations where you would like to emulate location changes at runtime. > **Caution:** > > **Attention!** > > You must still accept Location Service permissions on your headset when spoofing a location, even though GPS is not available on the device. ### Spoofing via NSDK Settings (image: Spoofing location and compass data in NSDK Settings) To get started spoofing locations and compass data, open the **NSDK** top menu in Unity, select **Settings**, and scroll down to the **Location & Compass** section. If necessary, change the **Data Source** from `Sensors` to `Spoof`. Changes are immediately picked up by `NianticSpatial.NSDK.AR.Input.location`. #### Spoof Location Info 1. **Latitude**: The simulated north/south coordinate. 2. **Longitude**: The simulated east/west coordinate. 3. **Timestamp**: When the location data was captured, in milliseconds since the Unix epoch. 4. **Altitude**: Simulated height above sea level, in meters. 5. **Horizontal Accuracy**: Uncertainty of the latitude/longitude, in meters. Lower = more accurate. 6. **Vertical Accuracy**: Uncertainty of the altitude, in meters. Lower = more accurate. #### Spoof Compass Info 1. **Magnetic Heading**: Direction to *magnetic north*, in degrees. `0` (or `360`) is north; `90` is east. 2. **True Heading**: Direction to *true north*, in degrees. Adjusted for magnetic declination (the difference between magnetic and true north). 3. **Heading Accuracy**: Uncertainty of the **True Heading**, in degrees. Lower = more accurate. 4. **Raw Vector**: The raw magnetometer data as a 3D vector (x, y, z), useful for computing orientation or tilt. 5. **Timestamp**: When the compass data was captured, in milliseconds since the Unix epoch. Typically aligns with the location timestamp. ### Spoofing via Script All of the aforementioned settings under **NSDK Settings** are configurable within a Unity script. To ensure your changes take effect, you must specify the data source for `NsdkSettingsHelper.ActiveSettings` by setting `LocationAndCompassDataSource` to `LocationDataSource.Spoof`. Alternatively, you can update this via NSDK settings as mentioned above. ```csharp // Important or you won't see your spoofed data! NsdkSettingsHelper.ActiveSettings.LocationAndCompassDataSource = LocationDataSource.Spoof; var locationInfo = NsdkSettingsHelper.ActiveSettings.SpoofLocationInfo; locationInfo.Latitude = 10.1f; locationInfo.Longitude = 20.2f; locationInfo.Altitude = 30.3f; locationInfo.HorizontalAccuracy = 40.4f; locationInfo.VerticalAccuracy = 50.5f; locationInfo.Timestamp = 12345678; var compassInfo = NsdkSettingsHelper.ActiveSettings.SpoofCompassInfo; compassInfo.MagneticHeading = 90f; compassInfo.TrueHeading = 1.43f; compassInfo.HeadingAccuracy = 1f; compassInfo.RawVector = new Vector3(0.1f, 0.2f, 0.3f); compassInfo.Timestamp = 123456; ```