Azure / azure-spatial-anchors-samples

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

InvalidOperationException : Could not find an ARAnchor associated with the CloudSpatialAnchor #358

Closed MisterYeti closed 2 years ago

MisterYeti commented 2 years ago

Hello,

Description I'am having an issue trying to FindAzureAnchor. I'm using the sample project on Unity 2020.3.19.

Steps to reproduce the issue After creating an Azure Anchor, I move the cube somewhere else, then i click on Find Azure Anchor so the cube is replaced where the anchors were created. But then, i try again to move the cube, and then Find Azure Anchor, but i get an InvalidOperationException telling me i Could not find an ARAnchor associated with the CloudSpatialAnchor

I don't understand why it's working only one time. The anchorLocateCriteria has the same ID that is stored locally.

First, i create the anchor Create

Then, after moving away the cube, i find the anchor Find1

And, after moving the cube again, i find the anchor again Find2

I'm probably missunderstanding something but I don't know why ! Any help would be very cool !

Development information Azure Spatial Anchors SDK Core 2.12.0 Azure Spatial Anchors SDK for Windows 2.12.0 Mixed Reality OpenXR Plugin 1.4.1

AR Device information Hololens 2

Varnauld commented 2 years ago

Hello, thank you for reaching out! Assigning this issue to @darax (tracking n#40207929)

darax commented 2 years ago

Hi @MisterYeti It might help to set the debug logging level on Azure Spatial Anchors to all, and get the unity log from the device from the device portal.

The log level can be set on the prefab with the SpatialAnchorManager script, and is probably already set to 'all'.

You can see the sample asking for the LogDebug callback here: https://github.com/Azure/azure-spatial-anchors-samples/blob/b6eb7a8f4f77130c1720fbd3418d9b911c544483/Unity/Assets/AzureSpatialAnchors.Examples/Scripts/DemoScriptBase.cs#L109 and handling the callback by writing to the log here: https://github.com/Azure/azure-spatial-anchors-samples/blob/b6eb7a8f4f77130c1720fbd3418d9b911c544483/Unity/Assets/AzureSpatialAnchors.Examples/Scripts/DemoScriptBase.cs#L573

The log will be on the device portal in a path similar to this: image

MisterYeti commented 2 years ago

Hello @darax,

Thank you for the answer !

Log level is indeed set to 'all' on SpatialAnchorManager script, and here are the logs : UnityPlayer.log

I Started an Azure Session, Created an Anchor, and then Find the Azure Anchor.

-> Anchor locate criteria configured to look for Azure anchor with ID 'e1cbb8e6-9d61-45b7-a251-fb9fabcc2a3d' -> Watcher created -> Looking for Azure anchor... please wait... -> Anchor recognized as a possible Azure anchor -> Azure anchor located successfully -> Local anchor position successfully set to Azure anchor position -> Setting object to anchor pose with position '(0,4, 0,3, 2,1)' and rotation '(0,2, -0,1, 0,1, -1,0)'

All good ! But when i Find the Azure Anchor a second time :

-> Anchor locate criteria configured to look for Azure anchor with ID 'e1cbb8e6-9d61-45b7-a251-fb9fabcc2a3d' -> Watcher created -> Looking for Azure anchor... please wait... -> Anchor recognized as a possible Azure anchor -> Azure anchor located successfully -> Local anchor position successfully set to Azure anchor position

and L 907 :

InvalidOperationException: Could not find an ARAnchor associated with the CloudSpatialAnchor.
  at Microsoft.Azure.SpatialAnchors.Unity.ARFoundation.AnchorHelpers.GetPose (Microsoft.Azure.SpatialAnchors.CloudSpatialAnchor cloudSpatialAnchor) [0x00000] in <00000000000000000000000000000000>:0 
  at Microsoft.Azure.SpatialAnchors.Unity.SpatialAnchorExtensions.GetPose (Microsoft.Azure.SpatialAnchors.CloudSpatialAnchor cloudAnchor) [0x00000] in <00000000000000000000000000000000>:0 
  at AnchorModuleScript+<>c__DisplayClass21_0.<CloudManager_AnchorLocated>b__1 () [0x00000] in <00000000000000000000000000000000>:0 
  at Microsoft.MixedReality.Toolkit.Examples.Demos.EyeTracking.TargetGroupIterator+TargetGroupEventHandler.Invoke () [0x00000] in <00000000000000000000000000000000>:0 
  at AnchorModuleScript.Update () [0x00000] in <00000000000000000000000000000000>:0 
darax commented 2 years ago

Hi @MisterYeti I don't see the ASA logging in the log, which makes me think that there isn't an event handler on LogDebug. I want to confirm, are you following the instructions here: https://docs.microsoft.com/en-us/learn/modules/azure-spatial-anchors-tutorials/ ? I've not actually gone through that tutorial series myself, is there a completed project that you start with or do you have to put it together yourself? If the former, I'll figure that out as I go through the tutorial to see my experience. :) If the latter, could you share your project somewhere (WITHOUT YOUR ASA CREDS IN THE PROJECT).

darax commented 2 years ago

Hi @MisterYeti I have reproduced the issue here. I will update you when I figure out what is wrong. No need to share anything else. :)

darax commented 2 years ago

Hi @MisterYeti Before searching for an anchor, you should stop the azure session and start it again. Alternatively, in AnchorModuleScript.FindAzureAnchor, you could change the anchorLocateCriteria to 'BypassCache': after: anchorLocateCriteria.Identifiers = anchorsToFind.ToArray(); add: anchorLocateCriteria.BypassCache = true;

The AnchorModuleScript has a bug which led to the issue, the if statement at the beginning of the function should be if (args.Status == LocateAnchorStatus.Located) rather than if (args.Status == LocateAnchorStatus.Located || ... AlreadyTracked)

MisterYeti commented 2 years ago

Hello @darax, thank you for investing that issue !

It works well with your fix, now I can Save and Load as many time as I want 👍 Thank you again for your time @darax :)

darax commented 2 years ago

@misteryeti Nice to actually resolve one of these. :) Cheers.

MisterYeti commented 2 years ago

https://youtu.be/jFxijhX8p1Q :-)

mikkeline-elleby commented 1 year ago

https://youtu.be/jFxijhX8p1Q :-)

Hi do you have a repo so I can try out this project and see the different settings ? I'm implementing collaboration on the hololens for my bachelor project and it would really help

MisterYeti commented 1 year ago

Hi @mikkeline-elleby, here is my repo : https://github.com/MisterYeti/MRTK_MultiExperienceAnchors Good luck for your project!

mikkeline-elleby commented 1 year ago

Thx