Files
cloud-mainworld/ufm cloud/Library/PackageCache/com.unity.xr.openxr@ef0033a586bf/Documentation~/native-api.md
T
2026-10-21 20:45:23 +01:00

2.8 KiB

uid
uid
openxr-native-api

OpenXR native API

For users familiar with the OpenXR specification, the class OpenXRNativeApi contains a partial public C# port of OpenXR. You can use the OpenXR native API to write low-level OpenXR code if you prefer a lower-level abstraction.

Refer to the OpenXR specification for more detailed information about each extension.

Supported extensions

The OpenXR native API currently supports the following OpenXR extensions:

Enable extensions

The OpenXR native API is a static class, so C# allows you to call its methods at any time from any C# script. However, methods provided by an extension will return the XrResult.FunctionUnsupported error code unless the required extension is enabled.

The OpenXR Plug-in supports enabling extensions via OpenXR features.

To enable the required extensions for the native API:

  1. Create a class that inherits OpenXRFeature.
  2. Fill out the required information for the OpenXRFeatureAttribute constructor, including the extensions you wish to enable.
  3. Implement OnInstanceCreate. Return false if any requirements to enable your feature are not met, such as if runtime failed to enable the required extensions.
  4. Go to Project Settings > XR Plug-in Management and enable your feature in the OpenXR tab.
  5. At runtime, use OpenXRSettings.Instance.GetFeature<T> to get your feature. If feature != null && feature.enabled, your app can use the native API methods provided by the enabled extensions.

Example code

The following example code demonstrates how to implement a simple OpenXR feature that enables XR_EXT_spatial_plane_tracking and its required dependencies:

[!code-csSpatialPlaneTrackingFeatureEXT]