Depth API in Unity's XR.Oculus (Deprecated)
Updated: Nov 10, 2026
Deprecated Oculus XR Plugin
This page describes the legacy Oculus XR Plugin integration and is retained for existing projects. For current development, use Unity’s OpenXR Plugin and the
EnvironmentDepthManager component in the Meta XR Core SDK. See
Get started with occlusions.
The Depth API itself is a much lower-level feature. It is exposed on the static Utils class in the Unity.XR.Oculus namespace and is referenced as Environment Depth.
The Depth API is supported on Meta Quest 3, Meta Quest 3S, and Meta VR Glasses. The feature has a function to check if it is supported.
Utils.GetEnvironmentDepthSupported()
To use Environment Depth, SetupEnvironmentDepth needs to be called to initialize runtime resources. When environment depth is no longer needed, and resources need to be freed, calling ShutdownEnvironmentDepth will clean everything up.
Utils.SetupEnvironmentDepth(EnvironmentDepthCreateParams createParams)
Utils.ShutdownEnvironmentDepth()
If the application hasn’t requested permission for USE_SCENE, the SetupEnvironmentDepth will perform it automatically. The service will start producing depth textures once the permission is granted.
After SetupEnvironmentDepth is called, the feature can be enabled/disabled in the runtime via:
public static void SetEnvironmentDepthRendering(bool isEnabled)
Note: Even if the application doesn’t consume Environment Depth textures, a performance overhead still exists if the feature is enabled. Make sure to call SetEnvironmentDepthRendering with isEnabled:false to improve performance.
To consume depth textures on each frame, you need to call this function:
Utils.GetEnvironmentDepthTextureId(ref uint id)
A successful query will return true. The texture ID is written to the ID ref parameter. This texture ID can be used to query a RenderTexture using XRDisplaySubsystem.GetRenderTexture. This RenderTexture can then be used in rendering or in compute shaders.
If you want to render virtual hands to replace the physical hands, this can result in depth fighting. In order to avoid this you can enable the hands removal feature which will remove hands from the environment depth texture and replace it with an approximate background depth. To check if the device supports it:
Utils.GetEnvironmentDepthHandRemovalSupported()
To toggle the feature, call:
Utils.SetEnvironmentDepthHandRemoval(bool enabled)
In addition to depth textures, applications can access per-eye metadata. It is returned in the form of the EnvironmentDepthFrameDesc struct. This contains useful information for more precise and advanced use of depth textures. To get the struct, call:
Utils.GetEnvironmentDepthFrameDesc(int eye)
It will return an EnvironmentDepthFrameDesc struct. It contains:
- The
isValid field indicates whether the depth frame is valid or not. If it is false, the other fields in the struct may contain invalid data. - The
createTime and predictedDisplayTime fields represent the time at which the depth frame was created and the predicted display time for the frame, respectively. - The
swapchainIndex field represents the index in the swap chain that contains the current depth frame. The current implementation doesn’t give you the ability to query a specific swapchain index. - The
createPoseLocation and createPoseRotation fields represent the location and rotation of the pose at the time the depth frame was created. - The
fovLeftAngle, fovRightAngle, fovTopAngle, and fovDownAngle fields represent the field of view angles of the depth frame. - The
nearZ and farZ fields represent the near and far clipping planes of the depth frame. - The
minDepth and maxDepth fields represent the minimum and maximum depth values of the depth frame.