Forum Discussion
hcpakman
3 years agoExplorer
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
Quick Links
- Horizon Developer Support
- Quest User Forums
- Troubleshooting Forum for problems with a game or app
- Quest Support for problems with your device
Other Meta Support
Related Content
- 2 months ago