docs.unity3d.com
    Show / Hide Table of Contents

    Implement a provider

    To implement a provider for one or more of the subsystems in this package (for example, say you are a hardware manufacturer for a new AR device), Unity recommends that your implementation inherit from that subsystem's base class. These base class types follow a naming convention of XRSubsystem, and they are found in the UnityEngine.XR.ARSubsystems namespace. Each subsystem base class has a nested abstract class called Provider, which is the primary interface you must implement for each subsystem you plan to support.

    Subsystem implementations should be independent from each other. For example, your implementation of the XRPlaneSubsystem should have the same behavior whether or not your XRPointCloudSubsystem implementation is also active in a user's scene.

    Register a subsystem descriptor

    Each subsystem type has a corresponding subsystem descriptor type. Your provider should create and register a subsystem descriptor instance with Unity's SubsystemManager to enable runtime discovery and activation of subsystems. To register your subsystem descriptor, include a static void method with the [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)] attribute as shown in the example below, and in it call the type-appropriate registration method for the type of subsystem descriptor you are registering.

    // This class defines a Raycast subsystem provider
    class MyRaycastSubsystem : XRRaycastSubsystem
    {
        class MyProvider : Provider
        {
            // ...
            // XRRaycastSubsystem.Provider is a nested abstract class for you 
            // to implement
            // ... 
        }
    
        // This method registers the subsystem descriptor with the SubsystemManager
        [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
        static void RegisterDescriptor()
        {
            // In this case XRRaycastSubsystemDescriptor provides a registration 
            // helper method. See each subsystem descriptor's API documentation 
            // for more information.
            XRRaycastSubsystemDescriptor.RegisterDescriptor(new XRImageTrackingSubsystemDescriptor.Cinfo
            {
                providerType = typeof(MyProvider),
                subsystemTypeOverride = typeof(MyRaycastSubsystem),
                // ...
                // You populate all required fields based on the details of 
                // your provider implementation
                // ...
            });
        }
    }
    

    Native plug-ins

    Some XR subsystems, notably including the mesh subsystem, are not defined in the ARSubsystems namespace. These subsystems conform to Unity's native plug-in interface, and their descriptors cannot be registered via C#. For more information about native plug-ins, see the Unity XR SDK documentation.

    Implement a tracking subsystem

    Each tracking subsystem defines a method called GetChanges, which reports all added, updated, and removed trackables since the previous call to GetChanges. You are required to implement the GetChanges method and should expect it to be called once per frame. Your provider must not update or remove a trackable without adding it first, nor update a trackable after it has been removed.

    Implement an XR Loader

    An XRLoader is responsible for creating and destroying subsystem instances based on the settings found in Project Settings > XR Plug-in Management. All provider plug-ins must implement an XRLoader. For more information on authoring an XRLoader, see the XR Plug-in Management provider documentation.

    Example XRLoader implementations can be found in existing provider plug-ins, such as the ARCoreLoader and ARKitLoader. Install these packages to view their source code.

    Back to top
    Copyright © 2023 Unity Technologies — Terms of use
    • Legal
    • Privacy Policy
    • Cookies
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)
    "Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
    Generated by DocFX on 18 October 2023