cancel
Showing results for 
Search instead for 
Did you mean: 

Spatial Anchor not loading after saving

magnimus_studios
Honored Guest

I am using deprecated Methods for creating and loading my spatial anchor in the game. But its not loaded again after saving. I also Update my rig with the building blocks.

And in the building blocks Spatial Anchor Core I am not able to get the spatial anchor from the meta script.

public class AnchorLoader : MonoBehaviour
{
    private OVRSpatialAnchor anchorPrefab;
    private AnchorManager anchorManager;

    Action<OVRSpatialAnchor.UnboundAnchor, bool> _onLoadAnchor;

    private void Awake()
    {
        anchorManager = GetComponent<AnchorManager>();
        anchorPrefab = anchorManager.spatialAnchorPrefab;
        _onLoadAnchor = onLocalized;
    }

    [Obsolete]
    public void LoadAnchorsByUuid()
    {
        if (!PlayerPrefs.HasKey("uuid"))
            return;

        var uuids = new Guid[1];
        var currentUuid = PlayerPrefs.GetString("uuid");
        uuids[0] = new Guid(currentUuid);

        Load(new OVRSpatialAnchor.LoadOptions
        {
            Timeout = 0,
            StorageLocation = OVRSpace.StorageLocation.Local,
            Uuids = uuids
        });
        ;
    }

    [Obsolete]
    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 anchor, bool success)
    {
        if (!success) 
        {
            PlayerPrefs.DeleteKey("uuid");
            return;
        }

        var pose = anchor.Pose;
        var spatialAnchor = Instantiate(anchorPrefab, pose.position, pose.rotation, GameManager.Instance.transform) ;
        anchor.BindTo(spatialAnchor);
        spatialAnchor.transform.GetComponent<ActiveWeaponAnchor>().SavedAnchor();

        if (spatialAnchor.TryGetComponent<OVRSpatialAnchor>(out var sAnchor))
        {
           /* var uuidText = spatialAnchor.GetComponentInChildren<Text>();
            var savedText = spatialAnchor.GetComponentsInChildren<Text>()[1];*/
/*
            uuidText.text = "UUID : " + spatialAnchor.Uuid.ToString();
            savedText.text = "Loaded From Device!";*/
        }
        anchorManager.GetLoadedAnchor(spatialAnchor);
        Debug.Log("Anchor Loaded");
        
    }
}

 

0 REPLIES 0