Showing results for 
Search instead for 
Did you mean: 

Problems with Spatial Anchors

Honored Guest



I've been having some issues for quite a while with spatial anchors. I tried to dabble with them some months ago with little success and now I'm trying again. I've had very inconsistent result with the samples where sometimes they work and other times I can't even place the anchor.

In my code all I want to do for now is call this function to place the anchor:


public void PlaceLeftAnchor(Vector3 position, Quaternion rotation)
    SpatialAnchor anchor = Instantiate(m_AnchorPrefab.GetComponent<SpatialAnchor>(), position, rotation);


 and here is the SpatialAnchor code based on the oculus samples:


using System.Collections;
using UnityEngine;

public class SpatialAnchor : MonoBehaviour
    private OVRSpatialAnchor m_SpatialAnchor = null;

    public string Uuid { get => m_Uuid; }
    private string m_Uuid = "";

    private IEnumerator Start()
        while (m_SpatialAnchor && !m_SpatialAnchor.Created)
            yield return null;

        Debug.LogError($"Achor created. Enabled?: {m_SpatialAnchor.enabled}");

    public void SaveAnchorLocally()
        Logger.Instance.LogError($"Saving anchor start. Status of anchor component: {m_SpatialAnchor == null} / {m_SpatialAnchor.enabled}");

        m_SpatialAnchor.Save((anchor, success) =>
            // --> Never reaches this part <--

        Logger.Instance.LogError($"End of Save Anchor");


 I don't manage to receive a callback within the m_SpatialAnchor.Save function and that seems to be the case due to the spatial anchor self-destructing itself. I get this error:


As a side note, I noticed that the anchors weren't working in the samples, until I added this line (<uses-permission android:name="com.oculus.permission.USE_ANCHOR_API" />) to the manifest. Now I was able to place and save the samples, but that wasn't enough to fix my own implementation. Perhaps I am missing more permissions?

If would greatly appreciate anyone who could provide insights or their own working example of a spatial anchor implementation.


Honored Guest

Which samples did you try?  The main SharedSpatialAnchors sample declares these 4 permissions/features:

<uses-feature android:name="android.hardware.vr.headtracking" android:version="1" android:required="true" />
<uses-permission android:name="com.oculus.permission.USE_ANCHOR_API" />
<uses-permission android:name="com.oculus.permission.IMPORT_EXPORT_IOT_MAP_DATA" android:required="false" />
<uses-feature android:name="com.oculus.feature.PASSTHROUGH" android:required="true" />