# Obtaining Depth and Ambient Depth Images in Unity Example

**URL:** <https://forum.magicleap.cloud/t/obtaining-depth-and-ambient-depth-images-in-unity-example/6078>\
**Category:** Unity Development\
**Tags:** unity, feature-request, openxr\
**Created:** [July 19, 2025, 3:15pm UTC](https://forum.magicleap.cloud/t/obtaining-depth-and-ambient-depth-images-in-unity-example/6078 "2025-07-19T15:15:06Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![graeme.rock](https://avatars.discourse-cdn.com/v4/letter/g/7ea924/32.png) [@graeme.rock](https://forum.magicleap.cloud/u/graeme.rock)\
**Post date:** [July 19, 2025, 3:15pm UTC](https://forum.magicleap.cloud/t/obtaining-depth-and-ambient-depth-images-in-unity-example/6078/1 "2025-07-19T15:15:06Z")

</div>

I am having difficulty figuring out how to access the ambient raw depth image and non-ambient raw depth image from the ML2 in Unity C#.

I am testing out of the `MagicLeapUnityExamples` project, so solutions within the `DepthCameraExample.cs` or `DepthStreamVisualizer.cs` example scripts would be fantastic.

I know from [this page](https://developer-docs.magicleap.cloud/docs/api-ref/api/Modules/group ___pixel_sensors/group___ d_cam/struct_m_l_depth_camera_frame/#mldepthcameraambientrawdepthimage-ambient-raw-depth-image) in the docs that the variables below are the variables I want to access. However, I am not seeing the means to access their struct for `MLDepthCameraFrame` based on the Unity example or the docs, only the `PixelSensorFrame`, unfortunately.

| Type / Name | Description |
| --- | --- |
| MLDepthCameraAmbientRawDepthImage \* ambient\_raw\_depth\_image | Ambient raw depth image. The illuminator in the sensor is modulated with a system determined frequency. This is the raw sensor data captured when the illuminator is off. |
| MLDepthCameraRawDepthImage \* raw\_depth\_image | Raw depth image. The illuminator in the sensor is modulated with a system determined frequency. This is the raw sensor data captured when the illuminator is on. |

Any help is much appreciated!

**Unity Editor version** : 2022.3  
**ML2 OS version** :  
**Unity SDK version** : 2.5.0  
**Host OS** : Windows 10

---

<div class="post-metadata">

**Author:** ![graeme.rock](https://avatars.discourse-cdn.com/v4/letter/g/7ea924/32.png) [@graeme.rock](https://forum.magicleap.cloud/u/graeme.rock)\
**Post date:** [July 21, 2025, 2:25pm UTC](https://forum.magicleap.cloud/t/obtaining-depth-and-ambient-depth-images-in-unity-example/6078/2 "2025-07-21T14:25:20Z")

</div>

Edit: I forgot that we had added [`DepthCameraExample.cs` and associated scripts from this doc](https://developer-docs.magicleap.cloud/docs/guides/unity-openxr/pixel-sensor/depth-camera-example/) into the same PixelSensor folder as the [`PixelSensorExample.cs`](https://github.com/magicleap/MagicLeapUnityExamples/tree/main/Assets/Scripts/PixelSensor) script when starting this project.  
I also forgot to add these example’s link in the main post (and can’t edit it apparently), so I’m doing it now!

---

<div class="post-metadata">

**Author:** ![magicbot](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.magicleap.cloud/magicbot/32/2470_2.png) [@magicbot](https://forum.magicleap.cloud/u/magicbot)\
**Post date:** [July 21, 2025, 3:48pm UTC](https://forum.magicleap.cloud/t/obtaining-depth-and-ambient-depth-images-in-unity-example/6078/3 "2025-07-21T15:48:57Z")

</div>

Unfortunately, You can NOT access both the raw and depth stream from the depth sensor using the Pixel Sensor API

---

<div class="post-metadata">

**Author:** ![graeme.rock](https://avatars.discourse-cdn.com/v4/letter/g/7ea924/32.png) [@graeme.rock](https://forum.magicleap.cloud/u/graeme.rock)\
**Post date:** [July 21, 2025, 3:55pm UTC](https://forum.magicleap.cloud/t/obtaining-depth-and-ambient-depth-images-in-unity-example/6078/4 "2025-07-21T15:55:22Z")

</div>

Ok, then what is the normal procedure for accessing `MLDepthCameraFrame`, so I may access `ambient_raw_depth_image` and `raw_depth_image`?

Would I access it from outside the `PixelSensorFrame` struct?

---

<div class="post-metadata">

**Author:** ![magicbot](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.magicleap.cloud/magicbot/32/2470_2.png) [@magicbot](https://forum.magicleap.cloud/u/magicbot)\
**Post date:** [July 22, 2025, 4:10pm UTC](https://forum.magicleap.cloud/t/obtaining-depth-and-ambient-depth-images-in-unity-example/6078/5 "2025-07-22T16:10:33Z")

</div>

The MLDepthCamera API that you linked is part of the MLSDK which has been deprecated. The Pixel Sensor API is the OpenXR replacement however it does not support accessing both Depth and Ambient images.

---

<div class="post-metadata">

**Author:** ![graeme.rock](https://avatars.discourse-cdn.com/v4/letter/g/7ea924/32.png) [@graeme.rock](https://forum.magicleap.cloud/u/graeme.rock)\
**Post date:** [July 22, 2025, 4:39pm UTC](https://forum.magicleap.cloud/t/obtaining-depth-and-ambient-depth-images-in-unity-example/6078/6 "2025-07-22T16:39:43Z")

</div>

Ah, I see…so my options are to use the MLSDK API to get both, or only the combined depth image with Pixel Sensor API in OpenXR - is that correct?

Are there any plans to expand the OpenXR package to be able to access both of the raw images?

---

<div class="post-metadata">

**Author:** ![magicbot](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.magicleap.cloud/magicbot/32/2470_2.png) [@magicbot](https://forum.magicleap.cloud/u/magicbot)\
**Post date:** [July 23, 2025, 8:18pm UTC](https://forum.magicleap.cloud/t/obtaining-depth-and-ambient-depth-images-in-unity-example/6078/7 "2025-07-23T20:18:47Z")

</div>

Unfortunately, this functionality is not on our roadmap but I did tag your ticket as a feature request to track the functionality developers are looking for.

---

<div class="post-metadata">

**Author:** ![graeme.rock](https://avatars.discourse-cdn.com/v4/letter/g/7ea924/32.png) [@graeme.rock](https://forum.magicleap.cloud/u/graeme.rock)\
**Post date:** [July 23, 2025, 8:46pm UTC](https://forum.magicleap.cloud/t/obtaining-depth-and-ambient-depth-images-in-unity-example/6078/8 "2025-07-23T20:46:25Z")

</div>

Ok, thanks!

Final follow-up question: can the MLSDK API be used alongside the OpenXR API [safely]?

---

<div class="post-metadata">

**Author:** ![kbabilinski](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.magicleap.cloud/kbabilinski/32/19_2.png) [@kbabilinski](https://forum.magicleap.cloud/u/kbabilinski)\
**Post date:** [July 24, 2025, 5:09pm UTC](https://forum.magicleap.cloud/t/obtaining-depth-and-ambient-depth-images-in-unity-example/6078/9 "2025-07-24T17:09:43Z")

</div>

Some of the APIs, yes : [Additional Features | MagicLeap Developer Documentation](https://developer-docs.magicleap.cloud/docs/guides/unity-openxr/additional-features/)

You can use the MLSDK Depth API however it is experimental and has known issues that will not be resolved due to the SDK being depricated.

---

<div class="post-metadata">

**Author:** ![graeme.rock](https://avatars.discourse-cdn.com/v4/letter/g/7ea924/32.png) [@graeme.rock](https://forum.magicleap.cloud/u/graeme.rock)\
**Post date:** [August 25, 2025, 3:54pm UTC](https://forum.magicleap.cloud/t/obtaining-depth-and-ambient-depth-images-in-unity-example/6078/10 "2025-08-25T15:54:08Z")

</div>

Appreciated!

Follow-up question: How do we actually get raw/brightness depth frames from the MLDepthCamera using MLSDK ?

We cannot find a depth example for MLSDK, and we keep getting a timeout failure from **`GetLatestDepthData`** and are not seeing what is missing.

We have successfully:

- **Gained permission** for the Depth Camera with `Permissions.RequestPermission(Permissions.DepthCamera,...etc)`

- **Connected** with `MLDepthCamera.Connect()`

- **Enabled short range** with  
`var settings = MLDepthCamera.CurrentSettings;`  
`settings.Streams = MLDepthCamera.Stream.ShortRange; MLDepthCamera.SetSettings(settings); `  
`MLDepthCamera.UpdateSettings(settings);`

We are not able to:

- **Set up `MLDepthCamera.Settings.StreamConfig`** , as it is null, and apparently cannot be set, according to the documentation?

What else do we need to do? Thanks.

---

<div class="post-metadata">

**Author:** ![kbabilinski](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.magicleap.cloud/kbabilinski/32/19_2.png) [@kbabilinski](https://forum.magicleap.cloud/u/kbabilinski)\
**Post date:** [August 26, 2025, 11:04pm UTC](https://forum.magicleap.cloud/t/obtaining-depth-and-ambient-depth-images-in-unity-example/6078/11 "2025-08-26T23:04:53Z")

</div>

Unfortunately, the MLSDK is deprecated and was experimental at the time. Because of this, there are outstanding bugs and the API is not recommended for production use.

The old version of the Magic Leap examples (1.12.0) may include the example for the API but I’m not sure.
