Saving spatial anchors and using on another app

I want to create spatial anchors as use them IDs. I want to use these IDs as inpiut in another app to position multiple set of objects. Whenever I open this App, it should locatet the designated objects by looking for the assigned IDs as locations of the objects. I read the spatial anchor documentation in unity and I have following questions.

  1. What I found in the documentation and example, that I can create spatial anchors using the given example unity project, but i dont understnad if those anchors created by the example project are saved in ML permanently and can be accessed or used by another applicaiton? if so how can we do it?
  2. Is bulilding the Unity example project the only way to assign spatial anchors or there are other ways. In my case, I just need to design a workflow where I dont need to take care of setting up the anchors when I open my final app and designated objects get localised on its own by presaved anchors.
  3. I could only find example and documentation for Unity, is this feature not well supported on Unreal, if so where can I find its doc and example project?

Is this a duplicate of the following post?


  1. Anchors created by the Unity and Unreal example project are created and can be "published" which saves the anchors to the space. They can later be queried using the Spatial Anchor Storage API. You can also visualize the saved anchors inside the Spaces app , by selecting the 3 dots next to the space and selecting View. A think white line will point to the origin of each anchor.
  2. No, you can create spatial anchors inside Unreal and Unity. Please see the Unreal Example project for more information
  3. I recommend using the tool that you are most familiar with.

Note, before using anchors you will need to map the spaces inside the Spaces app. Anchors can only be published to the map when you are localized (when the headset recognizes the environment you are in)

You can publish anchors in one app and query the anchors in another. The anchor query will return all of the anchors that are published.

1 Like

I tried building this project on my ML2 using the Unity example(GitHub - magicleap/SpatialAnchorsExample: Unity App that uses Magic Leap 2’s Spatial Anchors API and a JSON file to create content that persists in a Space across reboots. If the user is not localized, they the app allows users to localize using a QR Code.), it builds and opens, but the startup window says, it cant locate itself as the local space in not found, even though I made sure, the space is scanned and saved in the Space app.Ii made sure the permissions as per the documentation.

Also when I try to build the app on ML2, I get the following prompt:
PlayerSettings->Active Input Handling is set to Both, this is unsupported on Android and might cause issues with input and application performance. Please choose only one active input handling. Ignore and continue? (This dialog won't appear again in this Editor session if you'll choose Yes)"

I have doubts on the unity version and Magicleap SDK version requirements and if I should build it through MagicLeap provider or OpenXR provider. Problem persists on both latest Unity and 2022.2.0f1 for which the example project was built.

When you open the Space app, do you see a purple pin next to the name of the Space?

When you opened the project in 2022.2.0f1, was this after you tried to open it in a newer Unity version?

I would recommend using the Magic Leap 2 Unity Examples project, which shows how to use the latest SDK to query anchor positions. Additionally, if you are new to the field you can do the following:


Scan the Space and Download the Mesh:

  1. Scan the environment using the Spaces application. Take your time to make sure the space is scanned well.
  2. Once the space is saved, export the mesh into the downloads folder
  3. Attach your device to your computer and download the mesh from the Magic Leap 2 using the Magic Leap Hub 3
  4. Drag and Drop this mesh into the latest version of the Unity Examples Project

Download the GLTF Fast Package:

  1. Open the Package Manager in Unity
  2. Select the Plus Icon and select Add by name...
  3. Input the following name com.unity.cloud.gltfast and then select Install.
  4. Unity will load a little before the package is installed.

Add the Mesh to your scene:

  1. Once the package is installed, the GLB file inside Unity can be viewed as a Mesh.
  2. Drag and drop it into your scene. (You can choose any scene, including the spatial anchor scene.)
  3. The mesh will appear lightly red, you can change the material on the Mesh's Mesh Renderer if you like.

Align the mesh with the space origin:

  1. Add the the following script into your project.
    MapOriginTest.cs (1.9 KB)

  2. Attach it to am Empty Game Object and then assign the rootTransform parameter in the inspector to reference the exported Space.

The map will shift to match the space Origin when the app is deployed to the device.

Add objects:

  1. You can add additional virtual objects as children of the space origin.
  2. If you need to make modifications or changes, feel free to edit the script and check out the Localization Map section of the developer portal.

Important:

The space origin is a quick way to align objects in an environment. However, you unlike Spatial anchors, the origin cannot be changed once the space is created. This can lead to the origin being less accurate than a Spatial Anchor.

It looks like you were able to get it working :slight_smile: Anchoring Dynamic fire objects optimization

However, I recommend using the OpenXR API and the latest SDK instead of the project you referenced since it has not been updated to open XR yet.

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