Problems with WorldAnchors between Unity Player and deployed app

Hi,
we are trying to design our hololens application contents from the editor in remote mode, in order to fine-place holograms into the room and then attach world anchors to them when done. Everything works fine within the editor (we place our objects, we change their position, we restart everything after days and all our holograms are there in the the correct place).

But when we deploy our app on the device all our anchors cannot be loaded from the anchor store. We start again from the editor, the store includes our anchors.

The question is: when working with the editor in remote mode, where are the anchor stored? Apparently, not on the device (hololens) but locally. If this supposition is correct, how can we access them and possibly use them in the deployed version?

Here’s a short script that can reproduce the problem. Simply create an empty object, name it and attach the script. You can save the anchor pressing the ‘s’ key. At startup, the sript tries to load the anchor from the store. The sphere color tells you its state (white: sphere unlocked, green: anchor saved or loaded from store, red: anchor loading from store did not succeed, blue: saving anchor on store did not succeed). Start in editor remote mode, save your anchor (anchor should be green and in the same position the next execution) and then deploy the application (you should see a red sphere in front of the camera, wherever you viewing direction is at startup).

Thanks in advance for any possible help

using UnityEngine;
using UnityEngine.VR.WSA;
using UnityEngine.VR.WSA.Persistence;

public class AnchorPlacer : MonoBehaviour
{
    private bool loadAnchorAtStartup = true;
    protected WorldAnchorStore store = null;
    protected GameObject sphere = null;


    protected void StoreLoaded(WorldAnchorStore store)
    {
        this.store = store;
        if(loadAnchorAtStartup)
        LoadAnchor();
    }

    protected void Update()
    {
        // s key to save object anchor
        if(Input.GetKeyDown("s"))
        SaveAnchor();


        // c key to clear object anchor, thus allowing to change its position from the Unity editor
        if(Input.GetKeyDown("c"))
        {
        WorldAnchor anchor = gameObject.GetComponent<WorldAnchor>();
        if(anchor != null)
            DestroyImmediate(anchor);

        SetColor(sphere, Color.white);
        }
    }


    protected void SetColor(GameObject obj,Color color)
    {
        Renderer renderer = obj.GetComponent<Renderer>();
        if(renderer == null)
        return;

        renderer.material.color = color;
    }

    protected void Start()
    {
        sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere);
        sphere.transform.parent = transform;
        SetColor(sphere, Color.white);
        WorldAnchorStore.GetAsync(StoreLoaded);
    }

    public bool SaveAnchor()
    {
        //do the cleanup: if an anchor already exists, destroy it (from the gameobject and the store)
        WorldAnchor anchor = gameObject.GetComponent<WorldAnchor>();

        if(anchor != null)
        DestroyImmediate(anchor);

        if(store != null)
        {        
        store.Delete(gameObject.name);

        //add a game anchor to current object
        anchor = gameObject.AddComponent<WorldAnchor>();

        //save the anchor to the store
        if(!store.Save(gameObject.name, anchor))
        {
            Debug.LogWarning(string.Format("Anchor {0} NOT saved", gameObject.name));
            SetColor(sphere, Color.blue);
        }
        else
        {
            Debug.Log(string.Format("Anchor {0} successfully saved", gameObject.name));
            SetColor(sphere, Color.green);
            return true; //return true, because everything went all right
        }
        }
        else
        Debug.LogWarning(string.Format("Anchor {0} NOT saved because there's no access to the store", gameObject.name));

        //if we're here, we failed somehow
        return false;
    }

    public bool LoadAnchor()
    {
        //load the anchor of this object if available

        if(store != null)
        {        
        //get current world anchor (if it doesn't exist, add it)
        WorldAnchor anchor = gameObject.GetComponent<WorldAnchor>();

        if(anchor != null)
            DestroyImmediate(anchor);

        //load the anchor from the store
        if(!store.Load(gameObject.name, gameObject))
        {
            Debug.LogWarning(string.Format("Anchor {0} NOT loaded", gameObject.name));
            SetColor(sphere, Color.red);
        }
        else
        {
            Debug.Log(string.Format("Anchor {0} successfully loaded", gameObject.name));
            SetColor(sphere, Color.green);
            return true; //return true, because everything went all right
        }
        }
        else
        {
        Debug.LogWarning(string.Format("Anchor {0} NOT loaded because there's no access to the store", gameObject.name));
        SetColor(sphere, Color.yellow);
        }

        //if we're here, we failed somehow
        return false;
    }
}

2944765–218034–AnchorPlacer.cs (3.94 KB)

Hello,

I believe your going to have to do the setup on the Hololens with a deployed app. In remoting you are only streaming data back and forth from the hololens to the editor, I’m unsure how you would try grab the store from the editor and move it to the hololens.

I can ask a few questions with the team, but I think they will give a similar answer.

This might help be able to transfer the world anchors to the hololens.
https://docs.unity3d.com/ScriptReference/VR.WSA.Sharing.WorldAnchorTransferBatch.html

Let us know if you have questions.

first of all, thank you for the prompt reply. To comment your reply, we already tried as a workaround to save locally in the editor the worldanchors with transfer batch, and then load them at startup in the deployed version. However, apparently it is not possible to use WorldAnchorTransferBatch from within the editor, as we always get the following error: “SpatialAnchorTransferManager denied access to WorldAnchor serialization”. (see attached code)

Another option could be to send a message to the hololens asking to store locally (on the hololens) the world anchors (again with transfer batch), but, honestly, we have no idea how to do that. Do you have any suggestion?

Currently, our best option is to make a stub, deployed on the hololens, which communicates with unity editor: you place an anchor in the hololens, the stub send a message to the editor which creates the anchor you can modify. When done, you send from the editor a message to the stub to ask it to serialize the worldanchors, which are then loaded at startup by the deployed app that has to use them.

As you can see, the process is far from straighforward and we were hoping to find a simpler workaround…

2945576–218155–AnchorPlacer.cs (5.25 KB)

I’m not sure what the best way to handle this use case would be, I will see if anyone the team could provide more information.

Hello,

Have you found any good solutions yet? I’m currently having the same problem.

Thanks in advance

I got word back from some Microsoft that this simply isn’t supported. It’s a problem in the APIs they provide and not a problem with Unity.