cancel
Showing results for 
Search instead for 
Did you mean: 

OVRSpatialAnchor.Share() fails.

yutoVR
Protege

I'm testing Shared Spatial Anchors on Meta Quest Pro. The codes below.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class SpatialAnchorSender : MonoBehaviour
{
    [SerializeField]
    ulong partnerUserID;

    void Start()
    {
        StartCoroutine(Share());
    }

    IEnumerator Share()
    {
        var anchor = gameObject.AddComponent<OVRSpatialAnchor>();

        yield return new WaitUntil(() => anchor.Created);

        var anchors = new HashSet<OVRSpatialAnchor> { anchor };

        var user = new OVRSpaceUser(partnerUserID);
        var users = new HashSet<OVRSpaceUser> { user };

        OVRSpatialAnchor.Share(anchors, users, (collection, result) =>
        {
            if (result is OVRSpatialAnchor.OperationResult.Success)
            {
                Debug.Log($"Success sharing {collection.Count} anchor(s).");
            }
            else
            {
                Debug.LogError(result);
            }
        });
    }
}

 

Build it and run then I get logs below.

スクリーンショット 2022-12-20 201245.png

 

What's wrong? The 3rd log in OVRSpatialAnchor states Success:

var shareResult = OVRPlugin.ShareSpaces(spaces, handles, out var requestId);
if (shareResult == OVRPlugin.Result.Success)
{
    Development.LogRequest(requestId, $"Sharing {(uint)spaces.Length} spatial anchors...");
...

 

but 4th states Failure:

Development.LogRequestResult(requestId, result >= 0,
    succesMessage: $"Spaces shared.",
    failureMessage: $"Spaces share failed with error {result}.");

 

Here's my environment.

  • Windows 10
  • Unity 2021.3.15f1
  • Oculus Integration 47.0

 

If you have any idea, please help me.

Thank you.

2 ACCEPTED SOLUTIONS

Accepted Solutions

yutoVR
Protege

FYI, this is the code that succeeds in Share().

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Oculus.Platform;

public class SpatialAnchorSender : MonoBehaviour
{
    void Start()
    {
        StartCoroutine(Share());
    }

    IEnumerator Share()
    {
        var anchor = gameObject.AddComponent<OVRSpatialAnchor>();
        yield return new WaitUntil(() => anchor.Created);
        var anchors = new HashSet<OVRSpatialAnchor> { anchor };

        Core.Initialize();

        Users.GetLoggedInUser().OnComplete(message =>
        {
            var user = new OVRSpaceUser(message.GetUser().ID);
            var users = new HashSet<OVRSpaceUser> { user };
            var saveOptions = new OVRSpatialAnchor.SaveOptions { Storage = OVRSpace.StorageLocation.Cloud };

            OVRSpatialAnchor.Save(anchors, saveOptions, (collection, result) =>
            {
                if (result is not OVRSpatialAnchor.OperationResult.Success)
                {
                    Debug.LogError(result);
                    return;
                }

                OVRSpatialAnchor.Share(collection, users, (collection, result) =>
                {
                    if (result is OVRSpatialAnchor.OperationResult.Success)
                    {
                        Debug.Log("Success sharing anchor.");
                    }
                    else
                    {
                        Debug.LogError(result);
                    }
                });
            });
        });
    }
}

 

View solution in original post

2 REPLIES 2

yutoVR
Protege

The problem has solved. Thank you loic-all!

https://github.com/oculus-samples/Unity-SharedSpatialAnchors/issues/4

yutoVR
Protege

FYI, this is the code that succeeds in Share().

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Oculus.Platform;

public class SpatialAnchorSender : MonoBehaviour
{
    void Start()
    {
        StartCoroutine(Share());
    }

    IEnumerator Share()
    {
        var anchor = gameObject.AddComponent<OVRSpatialAnchor>();
        yield return new WaitUntil(() => anchor.Created);
        var anchors = new HashSet<OVRSpatialAnchor> { anchor };

        Core.Initialize();

        Users.GetLoggedInUser().OnComplete(message =>
        {
            var user = new OVRSpaceUser(message.GetUser().ID);
            var users = new HashSet<OVRSpaceUser> { user };
            var saveOptions = new OVRSpatialAnchor.SaveOptions { Storage = OVRSpace.StorageLocation.Cloud };

            OVRSpatialAnchor.Save(anchors, saveOptions, (collection, result) =>
            {
                if (result is not OVRSpatialAnchor.OperationResult.Success)
                {
                    Debug.LogError(result);
                    return;
                }

                OVRSpatialAnchor.Share(collection, users, (collection, result) =>
                {
                    if (result is OVRSpatialAnchor.OperationResult.Success)
                    {
                        Debug.Log("Success sharing anchor.");
                    }
                    else
                    {
                        Debug.LogError(result);
                    }
                });
            });
        });
    }
}