Forum Discussion

🚨 This forum is archived and read-only. To submit a forum post, please visit our new Developer Forum. 🚨
hcpakman's avatar
hcpakman
Explorer
3 years ago

OVRSpatialAnchor 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);
    }
 
 

2 Replies

Replies have been turned off for this discussion
  • (this is also my first coding forum post so dont roast me if i broke some unspoken rule or smth)

    • hcpakman's avatar
      hcpakman
      Explorer

      I actually figured it out on my own lol I hadn't updated the transform of the anchor I needed to save