docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Class ApiLayers

    Manages OpenXR API layers settings and operations within the Unity Editor. This class handles the importing, removing, reordering, and configuration of API layers for use in OpenXR applications, including all associated file operations.

    Inheritance
    object
    ApiLayers
    Inherited Members
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    object.ToString()
    Namespace: UnityEngine.XR.OpenXR
    Assembly: Unity.XR.OpenXR.dll
    Syntax
    [Serializable]
    public class ApiLayers
    Remarks

    The ApiLayers class provides comprehensive management of OpenXR API layers in your Unity project. API layers are middleware components that intercept OpenXR function calls to provide debugging, validation, or performance analysis capabilities. Use this class to programmatically configure which layers are active for your application. In the Unity Editor, you can import layers from JSON manifest files, enable or disable them, and control their order of execution.

    Examples

    This example demonstrates how to check and enable an API layer programmatically: ApiLayersFeature apiLayersFeature = OpenXRSettings.Instance.GetFeature<ApiLayersFeature>(); if (apiLayersFeature != null && !apiLayersFeature.apiLayers.IsEnabled("XR_APILAYER_LUNARG_core_validation")) { apiLayersFeature.apiLayers.SetEnabled("XR_APILAYER_LUNARG_core_validation", Architecture.X64, true); Debug.Log("Core validation layer enabled"); }

    Properties

    collection

    Gets a read-only list of the currently configured API layers.

    Declaration
    public IReadOnlyList<ApiLayers.ApiLayer> collection { get; }
    Property Value
    Type Description
    IReadOnlyList<ApiLayers.ApiLayer>
    See Also
    ApiLayers.ApiLayer
    ApiLayersFeature
    ApiLayers.ISupport

    Methods

    IsEnabled(string)

    Checks if a specific API layer is enabled for any architecture.

    Declaration
    public bool IsEnabled(string layerName)
    Parameters
    Type Name Description
    string layerName

    The name of the API layer to check the enabled state for across all architectures.

    Returns
    Type Description
    bool

    true if the layer exists and is enabled for at least one architecture; otherwise, false.

    Remarks

    This overload checks if the specified layer is enabled for at least one architecture in the collection. Use this method when you want to know if a layer is active anywhere in your project, regardless of the target architecture. This is useful for validation checks or when displaying layer status in the UI.

    Examples

    This example demonstrates checking if a layer is enabled for any architecture: ApiLayersFeature apiLayersFeature = OpenXRSettings.Instance.GetFeature<ApiLayersFeature>(); if (apiLayersFeature != null) { if (apiLayersFeature.apiLayers.IsEnabled("XR_APILAYER_LUNARG_core_validation")) { Debug.Log("Core validation layer is enabled for at least one architecture"); } }

    See Also
    ApiLayers.ApiLayer
    ApiLayersFeature
    ApiLayers.ISupport

    IsEnabled(string, Architecture)

    Checks if a specific API layer is enabled for the specified architecture.

    Declaration
    public bool IsEnabled(string layerName, Architecture libraryArchitecture)
    Parameters
    Type Name Description
    string layerName

    The name of the API layer to check the enabled state for (e.g., "XR_APILAYER_LUNARG_core_validation").

    Architecture libraryArchitecture

    The target architecture of the layer's library file to check (e.g., Architecture.X64).

    Returns
    Type Description
    bool

    true if the API layer exists and is enabled for the specified architecture; otherwise, false.

    Remarks

    Use this method to verify whether a specific API layer is currently active for a given architecture before attempting operations that depend on that layer. This is particularly useful when you have multiple architectures in your project and need to ensure a layer is enabled for the target platform. If the layer doesn't exist for the specified architecture, this method returns false.

    Examples

    This example shows how to check if a layer is enabled for a specific architecture: ApiLayersFeature apiLayersFeature = OpenXRSettings.Instance.GetFeature<ApiLayersFeature>(); if (apiLayersFeature != null) { bool isEnabled = apiLayersFeature.apiLayers.IsEnabled("XR_APILAYER_LUNARG_core_validation", Architecture.X64); Debug.Log($"Core validation layer for x64: {(isEnabled ? "enabled" : "disabled")}"); }

    See Also
    ApiLayers.ApiLayer
    ApiLayersFeature
    ApiLayers.ISupport

    SetEnabled(string, bool)

    Enables or disables a specific API layer by name, affecting all architectures.

    Declaration
    public void SetEnabled(string layerName, bool enabled)
    Parameters
    Type Name Description
    string layerName

    The name of the API layer to modify the enabled state for across all architectures.

    bool enabled

    The desired enabled state to set for all architectures of the specified API layer.

    Remarks

    This overload modifies the enabled state for all architectures of the specified layer. Use this when you want to enable or disable a layer across all platforms simultaneously, which is useful for global development or debugging scenarios. If you need architecture-specific control, use the overload that accepts an architecture parameter instead.

    Examples

    This example shows how to disable a layer for all architectures: ApiLayersFeature apiLayersFeature = OpenXRSettings.Instance.GetFeature<ApiLayersFeature>(); if (apiLayersFeature != null) { // Disable core validation for all architectures apiLayersFeature.apiLayers.SetEnabled("XR_APILAYER_LUNARG_core_validation", false); Debug.Log("Core validation layer disabled for all architectures"); }

    See Also
    ApiLayers.ApiLayer
    ApiLayersFeature
    ApiLayers.ISupport

    SetEnabled(string, Architecture, bool)

    Enables or disables a specific API layer by name and architecture.

    Declaration
    public void SetEnabled(string layerName, Architecture libraryArchitecture, bool enabled)
    Parameters
    Type Name Description
    string layerName

    The name of the API layer to check the enabled state for (e.g., "XR_APILAYER_LUNARG_core_validation").

    Architecture libraryArchitecture

    The target architecture of the layer's library file to modify.

    bool enabled

    The desired enabled state to set for the specified API layer (true to enable, false to disable).

    Remarks

    Use this method to control the enabled state of an API layer for a specific architecture at runtime or in Editor scripts. The changes take effect when the OpenXR instance is created. If the specified layer doesn't exist for the given architecture, this method has no effect. For build-time configuration, consider setting the layer state in the OpenXR settings UI instead.

    Examples

    This example shows how to enable a layer for a specific architecture: ApiLayersFeature apiLayersFeature = OpenXRSettings.Instance.GetFeature<ApiLayersFeature>(); if (apiLayersFeature != null) { // Enable core validation for x64 builds apiLayersFeature.apiLayers.SetEnabled("XR_APILAYER_LUNARG_core_validation", Architecture.X64, true); Debug.Log("Core validation layer enabled for x64"); }

    See Also
    ApiLayers.ApiLayer
    ApiLayersFeature
    ApiLayers.ISupport

    SetEnabled(ApiLayer, bool)

    Enables or disables a specific API layer.

    Declaration
    public void SetEnabled(ApiLayers.ApiLayer apiLayer, bool enabled)
    Parameters
    Type Name Description
    ApiLayers.ApiLayer apiLayer

    The API layer object to modify the enabled state for.

    bool enabled

    The desired enabled state to set for the specified API layer (true to enable, false to disable).

    Remarks

    This is a convenience overload that accepts an ApiLayer struct directly. Use this when you already have a reference to the layer object from the collection. This method modifies the enabled state for the specific architecture associated with the provided layer instance.

    Examples

    This example demonstrates enabling a layer using the ApiLayer object: ApiLayersFeature apiLayersFeature = OpenXRSettings.Instance.GetFeature<ApiLayersFeature>(); if (apiLayersFeature != null) { foreach (ApiLayers.ApiLayer layer in apiLayersFeature.apiLayers.collection) { if (layer.name == "XR_APILAYER_LUNARG_core_validation") { apiLayersFeature.apiLayers.SetEnabled(layer, true); } } }

    See Also
    ApiLayers.ApiLayer
    ApiLayersFeature
    ApiLayers.ISupport

    SetIndex(int, int)

    Sets an API layer to a new index in the list with its original index, affecting layer order.

    Declaration
    public bool SetIndex(int originalIndex, int destinationIndex)
    Parameters
    Type Name Description
    int originalIndex

    The current index of the API layer to move within the collection.

    int destinationIndex

    The target index to move the API layer to within the collection.

    Returns
    Type Description
    bool

    true if the API layer was successfully moved to the new index; otherwise, false if indices are invalid.

    Remarks

    Use this method to reorder layers when execution order matters for your debugging or validation workflow. The layer at originalIndex will be moved to destinationIndex, and other layers will shift accordingly. If either index is out of bounds, the method returns false and no changes are made.

    Examples

    This example demonstrates reordering layers by index: ApiLayersFeature apiLayersFeature = OpenXRSettings.Instance.GetFeature<ApiLayersFeature>(); if (apiLayersFeature != null) { // Move the layer at index 2 to index 0 (make it execute first) bool success = apiLayersFeature.apiLayers.SetIndex(2, 0); if (success) { Debug.Log("Layer reordered successfully"); } }

    See Also
    ApiLayers.ApiLayer
    ApiLayersFeature
    ApiLayers.ISupport

    SetIndex(string, Architecture, int)

    Sets an API layer to a new index in the list with its name and architecture, affecting layer order.

    Declaration
    public bool SetIndex(string layerName, Architecture libraryArchitecture, int destinationIndex)
    Parameters
    Type Name Description
    string layerName

    The name of the API layer to reposition within the collection.

    Architecture libraryArchitecture

    The architecture of the API layer's library file to reposition.

    int destinationIndex

    The target index to move the API layer to within the collection.

    Returns
    Type Description
    bool

    true if the API layer was successfully moved to the new index; otherwise, false if the layer was not found.

    Remarks

    Use this method to reorder a layer by name and architecture when you do not know its current index. This is useful when you know the layer you want to move but not its current position in the collection. The method returns false if no matching layer is found.

    Examples

    This example shows how to move a specific layer to the beginning of the list: ApiLayersFeature apiLayersFeature = OpenXRSettings.Instance.GetFeature<ApiLayersFeature>(); if (apiLayersFeature != null) { bool success = apiLayersFeature.apiLayers.SetIndex( "XR_APILAYER_LUNARG_core_validation", Architecture.X64, 0); if (success) { Debug.Log("Core validation layer moved to execute first"); } }

    See Also
    ApiLayers.ApiLayer
    ApiLayersFeature
    ApiLayers.ISupport

    SetIndex(ApiLayer, int)

    Sets an API layer to a new index in the list with its object instance, affecting layer order.

    Declaration
    public bool SetIndex(ApiLayers.ApiLayer apiLayer, int destinationIndex)
    Parameters
    Type Name Description
    ApiLayers.ApiLayer apiLayer

    The API layer object to move to a new position within the collection.

    int destinationIndex

    The target index to move the API layer to within the collection.

    Returns
    Type Description
    bool

    true if the API layer was successfully moved to the new index; otherwise, false.

    Remarks

    This convenience overload accepts an ApiLayer struct directly. Use this when you already have a reference to the layer object you want to reorder. The layer will be moved to the specified destination index in the collection.

    Examples

    This example demonstrates reordering using an ApiLayer object: ApiLayersFeature apiLayersFeature = OpenXRSettings.Instance.GetFeature<ApiLayersFeature>(); if (apiLayersFeature != null) { ApiLayers.ApiLayer layer = apiLayersFeature.apiLayers.collection[2]; bool success = apiLayersFeature.apiLayers.SetIndex(layer, 0); if (success) { Debug.Log($"Layer {layer.name} moved to first position"); } }

    See Also
    ApiLayers.ApiLayer
    ApiLayersFeature
    ApiLayers.ISupport

    TryAdd(string, Architecture, BuildTargetGroup, out ApiLayer)

    Adds a new API layer from a JSON manifest file. This method validates the manifest, copies the layer files into the project, and updates the settings.

    Declaration
    public bool TryAdd(string jsonPath, Architecture libraryArchitecture, BuildTargetGroup targetGroup, out ApiLayers.ApiLayer apiLayer)
    Parameters
    Type Name Description
    string jsonPath

    The absolute path to the JSON manifest file.

    Architecture libraryArchitecture

    The architecture of the api layer's library file.

    BuildTargetGroup targetGroup

    The build target group to use.

    ApiLayers.ApiLayer apiLayer

    The created API layer instance if successful.

    Returns
    Type Description
    bool

    True if the layer was successfully added, false otherwise.

    See Also
    ApiLayers.ApiLayer
    ApiLayersFeature
    ApiLayers.ISupport

    TryRemove(int)

    Removes an API layer by index. This cleans up the associated files from the project and removes the layer from the settings.

    Declaration
    public bool TryRemove(int layerIndex)
    Parameters
    Type Name Description
    int layerIndex

    Index of the layer to remove.

    Returns
    Type Description
    bool

    True if the layer was successfully removed, false otherwise.

    See Also
    ApiLayers.ApiLayer
    ApiLayersFeature
    ApiLayers.ISupport

    TryRemove(string, Architecture)

    Removes an API layer by name. This cleans up the associated files from the project and removes the layer from the settings.

    Declaration
    public bool TryRemove(string layerName, Architecture libraryArchitecture)
    Parameters
    Type Name Description
    string layerName

    Name of the layer to remove.

    Architecture libraryArchitecture

    Architecture of the layer to remove's library.

    Returns
    Type Description
    bool

    True if the layer was successfully removed, false otherwise.

    See Also
    ApiLayers.ApiLayer
    ApiLayersFeature
    ApiLayers.ISupport

    See Also

    ApiLayers.ApiLayer
    ApiLayersFeature
    ApiLayers.ISupport
    In This Article
    Back to top
    Copyright © 2026 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)