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)