# Locating MLSpatialAnchor in OpenXR

**URL:** <https://forum.magicleap.cloud/t/locating-mlspatialanchor-in-openxr/2955>\
**Category:** OpenXR\
**Created:** [December 11, 2023, 1:40pm UTC](https://forum.magicleap.cloud/t/locating-mlspatialanchor-in-openxr/2955 "2023-12-11T13:40:56Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![emaschino](https://avatars.discourse-cdn.com/v4/letter/e/13edae/32.png) [@emaschino](https://forum.magicleap.cloud/u/emaschino)\
**Post date:** [December 11, 2023, 1:40pm UTC](https://forum.magicleap.cloud/t/locating-mlspatialanchor-in-openxr/2955/1 "2023-12-11T13:40:56Z")

</div>

Hi,

[This is a follow-up to [ML Compat Extension (XR\_ML\_compat) support](https://forum.magicleap.cloud/t/ml-compat-extension-xr-ml-compat-support/2928), as suggested by @etucker]

I'm trying to locate in OpenXR the reference space associated with an anchor.

The anchor was created successfully as `MLSpatialAnchor` from MLPerception module as I can't find any way to do this in OpenXR. The anchor expiration date was set to 0 (_i.e._ no expiration) in `MLSpatialAnchorCreateInfo`. The anchor reference space was then created with `xrCreateSpaceFromCoordinateFrameUIDML` from ML Compat (`XR_ML_compat`) extension. The `MLCoordinateFrameUID` passed to `xrCreateSpaceFromCoordinateFrameUIDML` is given by anchor's `cfuid` member.

It's kinda working as `xrLocateSpace` returns a non-null/non-identity location. But neither `XR_SPACE_LOCATION_POSITION_VALID_BIT` nor `XR_SPACE_LOCATION_POSITION_TRACKED_BIT` is set. Is this expected? This is with latest ML SDK 1.4.0 and ML OS 1.4.1.

Out of curiosity, since creating an anchor requires to set up MLPerception and create a spatial anchor tracker, does it mean that both the MLPerception module and OpenXR runtime are concurrently tracking the world in background?

Thanks.

---

<div class="post-metadata">

**Author:** ![etucker](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.magicleap.cloud/etucker/32/842_2.png) [@etucker](https://forum.magicleap.cloud/u/etucker)\
**Post date:** [December 13, 2023, 11:04pm UTC](https://forum.magicleap.cloud/t/locating-mlspatialanchor-in-openxr/2955/2 "2023-12-13T23:04:04Z")

</div>

Hi @emaschino,

Thank you for creating a separate thread. This helps us keep the forums organized.

I have reached out to our team regarding your issue and I will report back as soon as I learn more.

Best,

El

---

<div class="post-metadata">

**Author:** ![etucker](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.magicleap.cloud/etucker/32/842_2.png) [@etucker](https://forum.magicleap.cloud/u/etucker)\
**Post date:** [December 15, 2023, 5:16pm UTC](https://forum.magicleap.cloud/t/locating-mlspatialanchor-in-openxr/2955/3 "2023-12-15T17:16:34Z")

</div>

Hi @emaschino,

Is the anchor locatable using C-API functions?

Are you calling MLPerceptionGetSnapshot every frame? This will update the position of the anchor in the PIL which needs to be updated manually.

Best,

El

---

<div class="post-metadata">

**Author:** ![emaschino](https://avatars.discourse-cdn.com/v4/letter/e/13edae/32.png) [@emaschino](https://forum.magicleap.cloud/u/emaschino)\
**Post date:** [December 19, 2023, 8:34am UTC](https://forum.magicleap.cloud/t/locating-mlspatialanchor-in-openxr/2955/4 "2023-12-19T08:34:56Z")

</div>

Hi @etucker,

Thanks for the update.

Well, I don't know if the anchor is locatable using the C API. I started to develop from scratch with OpenXR, as my app is cross-platform and also runs on Microsoft HoloLens 2 device.

I'm not calling `MLPerceptionGetSnapshot` at the moment. As there's no OpenXR sample in ML SDK showing how to use spatial anchors in OpenXR, I wasn't aware of this.

Now, looking at ML SDK C API spatial\_anchor sample, I'm wondering where to stop using C API _vs_ OpenXR. I mean, OK I must call `MLPerceptionGetSnapshot`. And also get the anchor transform with `MLSnapshotGetTransform`? What's then the purpose/benefit of using OpenXR's `xrLocateSpace` if I must stick that much with the C API?

---

<div class="post-metadata">

**Author:** ![emaschino](https://avatars.discourse-cdn.com/v4/letter/e/13edae/32.png) [@emaschino](https://forum.magicleap.cloud/u/emaschino)\
**Post date:** [December 22, 2023, 5:26pm UTC](https://forum.magicleap.cloud/t/locating-mlspatialanchor-in-openxr/2955/5 "2023-12-22T17:26:01Z")

</div>

I did have time to test calling `MLPerceptionGetSnapshot` prior to calling `xrLocateSpace`. No improvement, the returned location still has `XR_SPACE_LOCATION_POSITION_VALID_BIT` and `XR_SPACE_LOCATION_POSITION_TRACKED_BIT` unset.

---

<div class="post-metadata">

**Author:** ![etucker](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.magicleap.cloud/etucker/32/842_2.png) [@etucker](https://forum.magicleap.cloud/u/etucker)\
**Post date:** [January 4, 2024, 6:04pm UTC](https://forum.magicleap.cloud/t/locating-mlspatialanchor-in-openxr/2955/6 "2024-01-04T18:04:43Z")

</div>

Hi @emaschino,

I wanted to let you know that we are currently working on getting answers for you.

---

<div class="post-metadata">

**Author:** ![emaschino](https://avatars.discourse-cdn.com/v4/letter/e/13edae/32.png) [@emaschino](https://forum.magicleap.cloud/u/emaschino)\
**Post date:** [January 18, 2024, 1:14pm UTC](https://forum.magicleap.cloud/t/locating-mlspatialanchor-in-openxr/2955/7 "2024-01-18T13:14:53Z")

</div>

I just noticed the experimental `XR_ML_spatial_anchors` extension with Magic Leap OS/SDK update 1.5.0 (January 2024). Looks promising.

---

<div class="post-metadata">

**Author:** ![emaschino](https://avatars.discourse-cdn.com/v4/letter/e/13edae/32.png) [@emaschino](https://forum.magicleap.cloud/u/emaschino)\
**Post date:** [January 29, 2024, 1:08pm UTC](https://forum.magicleap.cloud/t/locating-mlspatialanchor-in-openxr/2955/8 "2024-01-29T13:08:22Z")

</div>

@etucker, just to let you know that I rewrote my code leveraging `XR_ML_spatial_anchors` extension. The `XR_SPACE_LOCATION_POSITION_VALID_BIT` and `XR_SPACE_LOCATION_POSITION_TRACKED_BIT` are now correctly set 🙂

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex019/uploads/magicleap1/original/1X/bd9b737a4d45ea243aa7eb177d60a773b806899a.svg) [@system](https://forum.magicleap.cloud/u/system)\
**Post date:** [February 13, 2024, 1:09pm UTC](https://forum.magicleap.cloud/t/locating-mlspatialanchor-in-openxr/2955/9 "2024-02-13T13:09:14Z")

</div>

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.
