/// <summary> /// Steps to show problem with XRAnchorStore.Clear() /// </summary> /// <param name="anchorStore">An empty XRAnchorStore</param> /// <param name="anchorTrackableId">TrackableId for an ARAnchor</param> private static void TestAnchorStore(XRAnchorStore anchorStore, TrackableId anchorTrackableId) { string anchorName = "Anchor0"; // Add the anchor to the anchorStore. Since anchorStore is empty, this succeeds. anchorStore.TryPersistAnchor(anchorTrackableId, anchorName); // Add the anchor again. Since it is already in the anchorStore, this fails with error message emitted. // This is correct and expected. anchorStore.TryPersistAnchor(anchorTrackableId, anchorName); // [XR] [Mixed Reality OpenXR Anchor]: Could not persist anchor "Anchor0"; name already used in anchor store. // Clear the anchorStore. anchorStore.Clear(); // It seems to have cleared everything, because the anchorStore.PersistedAnchorNames.Count == 0 now. // But attempting to persist Anchor0 again will still result in the same error. // INCORRECT HERE. anchorStore.TryPersistAnchor(anchorTrackableId, anchorName); // [XR] [Mixed Reality OpenXR Anchor]: Could not persist anchor "Anchor0"; name already used in anchor store. // Now Un-persist the anchor. anchorStore.UnpersistAnchor(anchorName); // Persisting it now seems to succeed (or at least generates no error message.) anchorStore.TryPersistAnchor(anchorTrackableId, anchorName); }
protected void OnDisable() { if (m_arAnchorManager != null) { m_arAnchorManager.anchorsChanged -= AnchorsChanged; m_anchorStore = null; m_incomingPersistedAnchors.Clear(); } }
private async Task <XRAnchorStore> EnsureWMRAnchorStore() { if (wmrAnchorStore == null) { DebugLogExtra($"Getting new WMR XRAnchorStore."); wmrAnchorStore = await xrAnchorManager.TryGetAnchorStoreAsync(); } wmrPersistence = wmrAnchorStore != null; return(wmrAnchorStore); }
private async Task <XRAnchorStore> EnsureOpenXRAnchorStore() { if (openXRAnchorStore == null) { DebugLogExtra($"Getting new OpenXR XRAnchorStore."); // openXRAnchorStore = await xrAnchorManager.LoadAnchorStoreAsync(); openXRAnchorStore = await XRAnchorStore.LoadAsync(xrAnchorManager); } openXRPersistence = openXRAnchorStore != null; return(openXRAnchorStore); }
private async Task <XRAnchorStore> EnsureOpenXRAnchorStore() { Debug.Assert(arAnchorManager != null, "Trying to open XRAnchorStore before creating ARAnchorManager."); if (openXRAnchorStore == null) { DebugLogExtra($"Getting new OpenXR XRAnchorStore."); // openXRAnchorStore = await arAnchorManager.LoadAnchorStoreAsync(); openXRAnchorStore = await XRAnchorStore.LoadAsync(arAnchorManager.subsystem); } openXRPersistence = openXRAnchorStore != null; return(openXRAnchorStore); }
protected async void OnEnable() { if (!TryGetComponent(out m_arAnchorManager) || !m_arAnchorManager.enabled || m_arAnchorManager.subsystem == null) { Debug.Log($"ARAnchorManager not enabled or available; sample anchor functionality will not be enabled."); return; } foreach (ARAnchor existingAnchor in m_arAnchorManager.trackables) { if (!m_anchors.Contains(existingAnchor)) { Debug.Log($"Anchor added from ARAnchorManager's trackables: {existingAnchor.trackableId}, OpenXR Handle: {existingAnchor.GetOpenXRHandle()}"); m_anchors.Add(existingAnchor); } } m_arAnchorManager.anchorsChanged += AnchorsChanged; m_anchorStore = await m_arAnchorManager.LoadAnchorStoreAsync(); if (m_anchorStore == null) { Debug.Log("XRAnchorStore not available, sample anchor persistence functionality will not be enabled."); return; } // Request all persisted anchors be loaded once the anchor store is loaded. foreach (string name in m_anchorStore.PersistedAnchorNames) { // When a persisted anchor is requested from the anchor store, LoadAnchor returns the TrackableId which // the anchor will use once it is loaded. To later recognize and recall the names of these anchors after // they have loaded, this dictionary stores the TrackableIds. TrackableId trackableId = m_anchorStore.LoadAnchor(name); m_incomingPersistedAnchors.Add(trackableId, name); } }