Azure / azure-spatial-anchors-samples

Azure Spatial Anchors sample code
Other
293 stars 139 forks source link

Hololens 2 - Anchor located don't set real position after instantiate. #188

Closed ericloureiro closed 4 years ago

ericloureiro commented 4 years ago

I'm following the Tutorial: Create a new HoloLens Unity app using Azure Spatial Anchors and when an anchor is located, the position is always on the HoloLens position (Vector3.zero).

In Output it shows some generic exceptions thrown in dlls that may have been interfering (print below).

Tutorial code:

private void CloudSpatialAnchorSession_AnchorLocated(object sender, AnchorLocatedEventArgs args)
{
    switch (args.Status)
    {
        case LocateAnchorStatus.Located:
            Debug.Log("ASA Info: Anchor located! Identifier: " + args.Identifier);
            QueueOnUpdate(() =>
            {
                // Create a green sphere.
                sphere = GameObject.Instantiate(spherePrefab, Vector3.zero, Quaternion.identity) as GameObject;
                sphere.AddComponent<WorldAnchor>();
                sphereMaterial = sphere.GetComponent<MeshRenderer>().material;
                sphereMaterial.color = Color.green;

                // Get the WorldAnchor from the CloudSpatialAnchor and use it to position the sphere.
                sphere.GetComponent<UnityEngine.XR.WSA.WorldAnchor>().SetNativeSpatialAnchorPtr(args.Anchor.LocalAnchor);

                // Clean up state so that we can start over and create a new anchor.
                cloudSpatialAnchorId = "";
                tapExecuted = false;
            });
            break;
    }
}

My code:

private void OnAnchorLocated(object sender, AnchorLocatedEventArgs args)
    {
        switch (args.Status)
        {
            case LocateAnchorStatus.Located:
                Debug.Log("Anchor located: " + args.Anchor.Identifier);

                QueueOnUpdate(() =>
                {
                    anchor = GameObject.Instantiate(anchorPrefab, Vector3.zero, Quaternion.identity) as GameObject;
                    anchor.AddComponent<WorldAnchor>();

                    anchor.GetComponent<WorldAnchor>()SetNativeSpatialAnchorPtr(args.Anchor.LocalAnchor);

                    Debug.Log("Anchor cloud to native done");
                });
                break;
        }
    }

Debug Output: image

Tried different ways to set position, as utilizing ASA SDK (that in the and do the same as above):

anchor.AddComponent<CloudNativeAnchor>();
anchor.GetComponent<CloudNativeAnchor>().CloudToNative(args.Anchor);

Any suggestions?

ericloureiro commented 4 years ago

Changed back to Unity from 2019.3.X to 2019.2.X and XR Management to Windows Mixed Reality (deprecated) and now everything works fine. Closing Issue.