Integrate OpenXR features
OpenXR is an extensible API that you can extend with new features. To facilitate this within the Unity ecosystem, the Unity OpenXR provider supports a feature extension mechanism.
Important
This section of the OpenXR package documentation is for developers integrating the OpenXR features provided by an XR device. If you are developing an XR application, refer to Feature Management for information about how to enable features provided by the XR packages you have installed in your project. App developers typically don't create features or feature groups.
Examples of what you can do with a custom feature include:
Intercepting OpenXR function calls: To intercept OpenXR function calls, override
OpenXRFeature.HookGetInstanceProcAddr. Returning a different function pointer allows intercepting any OpenXR method. For an example, refer to theIntercept Featuresample.Calling OpenXR functions from a feature: To call an OpenXR function within a feature you first need to retrieve a pointer to the function. To do this use the
OpenXRFeature.xrGetInstanceProcAddrfunction pointer to request a pointer to the function you want to call. UsingOpenXRFeature.xrGetInstanceProcAddrto retrieve the function pointer ensures that any intercepted calls set up by features usingOpenXRFeature.HookGetInstanceProcAddrwill be included.Providing a Unity subsystem implementation:
OpenXRFeatureprovides several XR Loader callbacks where you can manage the lifecycle of Unity subsystems. For an example meshing subsystem feature, refer to theMeshing Subsystem Featuresample.Note
A
UnitySubsystemsManifest.jsonfile is required in order for Unity to discover any subsystems you define. At the moment, there are several restrictions around this file:- It must be only 1 subfolder deep in the project or package.
- The native library it refers to must be only 1-2 subfolders deeper than the
UnitySubsystemsManfiest.jsonfile. - The native library it refers to must be only 1-2 subfolders deeper than the
UnitySubsystemsManifest.jsonfile.
Supporting OpenXR interaction profiles: To support OpenXR interaction profiles that aren't currently supported by the Unity OpenXR settings, you can implement a
OpenXRInteractionFeaturesubclass.Requiring a more recent or custom OpenXR loader library: you can specify that your feature requires a minimum version of the standard OpenXR loader library or that it requires a custom loader library that you supply.
Refer to the following topics for information about implementing OpenXR features:
| Topic | Description |
|---|---|
| Create OpenXR features | How to add features. |
| Define OpenXR feature groups | How to define groups to organize OpenXR features. |
| Create OpenXR interaction features | How to add support for interaction profiles. |
| Require a custom loader library | How to require a custom loader library for features. |