Search Unity

WorldAnchorTransferBatch.ImportAsync never completes

Discussion in 'VR' started by ar_life, Dec 16, 2018.

  1. ar_life

    ar_life

    Joined:
    Oct 15, 2014
    Posts:
    2
    I need to share anchors between different apps on the Hololens, so I followed the guide at

    https://docs.microsoft.com/en-us/windows/mixed-reality/shared-experiences-in-unity

    to store the anchor information into a byte array. When I try to load the anchor from this byte array the call to WorldAnchorTransferBatch.ImportAsync never completes (i.e., a Debug line in the OnComplete function never gets called even if I wait for 15 minutes).

    Here is a rough outline of the code:

    Code (CSharp):
    1. byte[] anchordata = new byte[] {};
    2. bool completed_storing=false;
    3.  
    4. public void StoreAnchor()
    5. {
    6.     UnityEngine.XR.WSA.Sharing.WorldAnchorTransferBatch transferBatch = new UnityEngine.XR.WSA.Sharing.WorldAnchorTransferBatch();
    7.     transferBatch.AddWorldAnchor("Anchor", this.gameObject.GetComponent<UnityEngine.XR.WSA.WorldAnchor>());
    8.     UnityEngine.XR.WSA.Sharing.WorldAnchorTransferBatch.ExportAsync(transferBatch, OnExportDataAvaliable, OnExportComplete);
    9. }
    10.  
    11. private void OnExportDataAvaliable(byte[] data)
    12. {
    13.     anchordata = anchordata.Concat(data).ToArray();
    14. }
    15.  
    16. protected void OnExportComplete(UnityEngine.XR.WSA.Sharing.SerializationCompletionReason completionReason)
    17. {
    18.     if (completionReason != UnityEngine.XR.WSA.Sharing.SerializationCompletionReason.Succeeded)
    19.     {
    20.         Debug.Log("Failed Export: " + completionReason.ToString());
    21.     }
    22.     else
    23.     {
    24.         Debug.Log("export completed");
    25.         completed_storing = true;
    26.     }
    27. }
    28.  
    29. void Update()
    30. {
    31.     if (completed_storing)
    32.     {
    33.         completed_storing = false;
    34.         Debug.Log("loading");
    35.         UnityEngine.XR.WSA.Sharing.WorldAnchorTransferBatch.ImportAsync(anchordata, OnImportComplete);
    36.     }
    37.  
    38. private void OnImportComplete(UnityEngine.XR.WSA.Sharing.SerializationCompletionReason completionReason, UnityEngine.XR.WSA.Sharing.WorldAnchorTransferBatch deserializedTransferBatch)
    39. {
    40.     Debug.Log("Loading completed");
    41. }
    The same problem persists when I store the information to a file and try to load it on program start.

    I have built and deployed the application in .NET and IL2CPP to the actual Hololens. The Debug information (and the file stored on the device) shows that the anchor is about 5-10 MB. I tried building the app in Unity 2017.4, 2018.2.4, 2018.3 with the same result.

    Has anyone else experienced something similar?
     
    Last edited: Dec 16, 2018
  2. Unity_Wesley

    Unity_Wesley

    Unity Technologies

    Joined:
    Sep 17, 2015
    Posts:
    558
    I think you are missing the step of creating the store to store and anchors you wish to transfer. Let me know if you have more questions
     
  3. ar_life

    ar_life

    Joined:
    Oct 15, 2014
    Posts:
    2
    That raises several questions, why would I need a store if WorldAnchorTransferBatch works for each anchor object (from the documentation it is not clear that a store is required in any way).

    Even adding the anchor to the store through

    Code (CSharp):
    1.  
    2.  
    3. UnityEngine.XR.WSA.Persistence.WorldAnchorStore store;
    4. UnityEngine.XR.WSA.Persistence.WorldAnchorStore.GetAsync(StoreLoaded);
    5.  
    6. and
    7.  
    8. store.Save("Anchor", this.gameObject.GetComponent<UnityEngine.XR.WSA.WorldAnchor>());
    9.  
    changes nothing. It I use only WorldAnchorStore to save and load the anchor it works perfectly, which is ok if I run only 1 app. But it does not allow sharing with other applications that should reuse the same anchor.

    For now I am making a workaround where all apps are bundled into a single app and the user can select which one he wants to execute.
     
  4. Masasui

    Masasui

    Joined:
    May 8, 2017
    Posts:
    2
    Sorry to ressurect this old thread, but this is currently an issue for me too. I am trying to Import an anchor from a file, but the ImportAsync onComplete method is never called. My anchor is roughly 16MB.
     
  5. joejo

    joejo

    Unity Technologies

    Joined:
    May 26, 2016
    Posts:
    958
  6. Masasui

    Masasui

    Joined:
    May 8, 2017
    Posts:
    2
    Hi, thanks for your reply. I actually am using legacy XR support in Unity 2019.4 and targeting UWP for HoloLens 2 deployment. When I try to Import the anchor, my app either freezes (anchor bytes transfered via socket; anchor is available upon restart), or does nothing (anchor bytes via file; anchor never becomes available)
     
  7. joejo

    joejo

    Unity Technologies

    Joined:
    May 26, 2016
    Posts:
    958
    Can you please file a bug and report the case id here?