Loading unbound anchors returns [0 or anchors_count_till_last_session] (NOT null)
I saved the anchors' uuid in the playerprefs after creating them - it's getting created successfully. Then, I tried to load the anchors in the same session without quitting the app (my use case is to visually clear the anchors after saving and loading them on the user's command) - the resultant anchors-array from LoadingUnboundAnchors is NOT null but it contains only anchors from last session. Once I quit and reopen the app, the anchors are loading successfully. I want to load them before quitting the app as well (I mean in the same session). Any ideas on why this is not happening?? Or any suggestions on how to implement this? OVRSpatialAnchor.LoadUnboundAnchorsAsync(loadOptions).ContinueWith(anchors => { if(anchors == null) { Debug.Log("Anchor Sample: Load anchors failed with null result."); } Debug.Log($"Anchor Sample: anchors available {anchors.Length}"); //length is zero if loaded in the same session or it is equal to the number of anchors created till the last session });313Views0likes0CommentsSpatial Anchors bug: LoadUnboundAnchors returns null UUIDList
Hi, I am struggling trying to work with Spatial Anchors and what looks like a bug. I am creating a few gameobjects in the virtual room, adding Space Anchors to them, saving the room anchors to local storage and reloading them. I save the uuid list so I can reload the objects even if I close the app and run it again. It works fine but, in some "random" situations, the LoadUnboundAnchors returns a null UUIDList as if it were no Unbound anchors to be loaded. When this happens I can try and try to load them but always get the same result. But... if I create a new anchor in the session and save it, then I can reload all of them.🙄 Once they are loaded I can remove all objects and anchors and reload again and works fine. So, it looks that I cannot load correctly the saved anchors unless I have previously saved one in the same session. I know that they are correctly saved because after creating a new anchor in the empty room I reload them succesfully. Anyone else have this problem? I am using Quest 2, Unity 2022.3.11, Meta XR Core 59. The loading sequence is something like this: OVRSpatialAnchor.LoadOptions options = new OVRSpatialAnchor.LoadOptions { Timeout = 0, StorageLocation = OVRSpace.StorageLocation.Local, Uuids = GetSavedAnchorsUuids() }; OVRSpatialAnchor.LoadUnboundAnchors(options, _anchorSavedUUIDList => { if (_anchorSavedUUIDList == null) { //Debug.Log("Anchor list is null!"); return; } .... }1.4KViews0likes1CommentProblems with Spatial Anchors
Hello, 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); anchor.SaveAnchorLocally(); } and here is the SpatialAnchor code based on the oculus samples: using System.Collections; using UnityEngine; [RequireComponent(typeof(OVRSpatialAnchor))] public class SpatialAnchor : MonoBehaviour { [SerializeField] 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.2.2KViews0likes1CommentOVRSpatialAnchor not appearing to save at/load from the right place in world space
I'm trying to implement a locally-saved spatial anchor system, but every time I try to load a saved anchor and instantiate an anchor prefab to the previously saved location it just ends up loading at some point close to (but never quite at) (0,0,0) instead of wherever I actually placed the anchor. Would love some help figuring this out because I have no idea where I went wrong 😞 Save code: // save anchor locally anchor.Save((anchor, success) => { if (!success) { return; } // save anchor to player prefs (persistent) PlayerPrefs.SetString("main_uuid", anchor.Uuid.ToString()); }); Load code: var main_uuid = new Guid(PlayerPrefs.GetString("main_uuid")); var uuids = new Guid[1]; uuids[0] = main_uuid; Load(new OVRSpatialAnchor.LoadOptions { Timeout = 0, StorageLocation = OVRSpace.StorageLocation.Local, Uuids = uuids }); private void Load(OVRSpatialAnchor.LoadOptions options) => OVRSpatialAnchor.LoadUnboundAnchors(options, anchors => { if (anchors == null) { return; } foreach (var anchor in anchors) { if (anchor.Localized) { _onLoadAnchor(anchor, true); } else if (!anchor.Localizing) { anchor.Localize(_onLoadAnchor); } } }); private void OnLocalized(OVRSpatialAnchor.UnboundAnchor unboundAnchor, bool success) { if (!success) { return; } var pose = unboundAnchor.Pose; var spatialAnchor = Instantiate(anchor_prefab, pose.position, pose.rotation); unboundAnchor.BindTo(spatialAnchor); }1.7KViews0likes2Comments