SZS
SZS

Reputation: 43

Using WorldAnchorManager form Holotoolkit

I'm trying to use WorldAnchorManager in order to move an object, save its position and after restarting the application, find it in the position. I'm using vocal comand for call the method for appling anchors and delete it.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using HoloToolkit.Unity;


public class AnchorScript : MonoBehaviour
{
public WorldAnchorManager worldAnchorManager;
private string anchorName="1";

// Start is called before the first frame update
void Start()
{
   
    AnchorIt();
}

// Update is called once per frame
void Update()
{
    
}




public void AnchorIt()
{
    WorldAnchorManager.Instance.AttachAnchor(this.gameObject,anchorName);
    this.gameObject.GetComponent<Renderer>().material.color = Color.red;
    

}

public void ReleaseAnchor()
{
   WorldAnchorManager.Instance.RemoveAnchor(this.gameObject);
    this.gameObject.GetComponent<Renderer>().material.color = Color.gray;
  
}

}

When I call AnchorIt () the object turns red and I can't move it to another location. So far everything ok. So when I close the application and restart it, the object is in the previous position and not where I move it. I have to point out that I use the Hololens emulator, because I can't use them every time.

(The WorldAnchorManager is a separate prefab, that I pass to the object. And the object that i want to move has the AnchorScript) Anyone can help me?

I have another question: are there any different between the anchors of Holotoolkit package and Azure anchors?

Upvotes: 0

Views: 136

Answers (1)

Sarah Zhang - MSFT
Sarah Zhang - MSFT

Reputation: 36

When you restart the game, the temporary cache of the anchor would be cleared, you can’t restore the data from the previous cache. To store the anchor persistently, you can write the corresponding location information to a binary file then store the file in the local disk. Or you can consider storing the data to Unity pre-defined object PlayerPrefs directly.

The Azure Anchors and the anchor of Holotoolkit or MRTK are different concepts. Azure Spatial Anchors is a cross-platform cloud service that allows you to create mixed reality experiences using objects that persist their location across devices over time. Azure Object Anchors is designed to detect an object in the physical world using a 3D model and estimate its 6DoF pose. The anchor of Holotoolkit is used to locate and track the hologram, it’s the implementation of the Spatial anchors. You can click the above links to check the documents of these concepts.

In addition, please note that we have updated the Holotoolkit to MixedRealityToolkit. We would suggest you use the MRTK to prevent missing the latest updates.

Upvotes: 1

Related Questions