docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Occlusion

    This page supplements the AR Foundation Occlusion manual. The following sections only contain information about APIs where Google's Android XR runtime exhibits platform-specific behavior.

    Tip

    When developing an AR app, refer to both the AR Foundation documentation as well as the required packages for each platform you support.

    Optional feature support

    Android XR implements the following optional features of AR Foundation's XROcclusionSubsystem:

    Feature Descriptor Property Supported
    Environment Depth Image environmentDepthImageSupported Yes
    Environment Depth Confidence Image environmentDepthConfidenceImageSupported Yes
    Environment Depth Temporal Smoothing environmentDepthTemporalSmoothingSupported Yes
    Human Segmentation Stencil Image humanSegmentationStencilImageSupported
    Human Segmentation Depth Image humanSegmentationDepthImageSupported

    Occlusion samples

    AR Foundation provides the HMDOcclusion sample to demonstrate occlusion on head-mounted displays (HMDs). For more information about HMD occlusion, refer to AR Shader Occlusion component (AR Foundation).

    To test occlusion on Android XR with the occlusion sample:

    1. Clone the AR Foundation Samples repo from the AR Foundations Samples GitHub repository and open it in Unity.
    2. Open the HMDOcclusion scene in Unity from Assets/Scenes/Occlusion/HMDOcclusion.
    3. Create a new material and set its shader to Assets/Shaders/Occlusion/OcclusionSimpleLit/OcclusionSimpleLit.shader. Refer to Creating Materials for more information about creating and applying materials.
    4. Apply the new material to a sample cube in the scene and position as desired.
    5. Open the AROcclusionManager in the Inspector window, and disable Temporal Smoothing.

    Permissions

    AR Foundation's occlusion detection feature requires an Android system permission on the Android XR runtime. Your user must grant your app the android.permission.SCENE_UNDERSTANDING_FINE permission before it can track occlusion data.

    To avoid permission-related errors at runtime, set up your scene with the AR Occlusion Manager component disabled, then enable it only after the required permission is granted.

    The following example code demonstrates how to handle required permissions and enable the AR Occlusion Manager component:

            const string k_Permission = "android.permission.SCENE_UNDERSTANDING_FINE";
    
            [SerializeField]
            AROcclusionManager m_AROcclusionManager;
    
    #if UNITY_ANDROID
            void Start()
            {
                if (!Permission.HasUserAuthorizedPermission(k_Permission))
                {
                    var callbacks = new PermissionCallbacks();
                    callbacks.PermissionDenied += OnPermissionDenied;
                    callbacks.PermissionGranted += OnPermissionGranted;
    
                    Permission.RequestUserPermission(k_Permission, callbacks);
                }
                else
                {
                    // enable the AR Occlusion Manager component if permission is already granted
                    m_AROcclusionManager.enabled = true;
                }
            }
    
            void OnPermissionDenied(string permission)
            {
                // handle denied permission
            }
    
            void OnPermissionGranted(string permission)
            {
                // enable the AR Occlusion Manager component if permission is already granted
                m_AROcclusionManager.enabled = true;
                m_AROcclusionManager.subsystem.Stop();
                m_AROcclusionManager.subsystem.Start();
            }
    #endif // UNITY_ANDROID
    

    For a code sample that involves multiple permissions in a single request, refer to the Permissions page.

    In This Article
    Back to top
    Copyright © 2025 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)