Hello everyone.

The Mixed Reality Forums here are no longer being used or maintained.

There are a few other places we would like to direct you to for support, both from Microsoft and from the community.

The first way we want to connect with you is our mixed reality developer program, which you can sign up for at https://aka.ms/IWantMR.

For technical questions, please use Stack Overflow, and tag your questions using either hololens or windows-mixed-reality.

If you want to join in discussions, please do so in the HoloDevelopers Slack, which you can join by going to https://aka.ms/holodevelopers, or in our Microsoft Tech Communities forums at https://techcommunity.microsoft.com/t5/mixed-reality/ct-p/MicrosoftMixedReality.

And always feel free to hit us up on Twitter @MxdRealityDev.
Options

can't save WorldAnchor

ar4dsar4ds
edited May 2017 in Questions And Answers

i can't add WorldAnchor into WorldAnchorStore
attachment is an Unity Project, and tap event will call add WorldAnchor.
my environment is unity5.6 + Hololens Enumerator.


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.VR.WSA.Input;
using UnityEngine.VR.WSA;
using UnityEngine.VR.WSA.Persistence;
using UnityEngine.UI;

public class Test : MonoBehaviour
{
public Transform prefabTran;
public Text text;
List was = new List();
WorldAnchorStore store;
GestureRecognizer gestureR;

void Start()
{
    InitGesture();
    WorldAnchorStore.GetAsync(myAsyncDelegate);
    WorldStoreInstance();
}

void InitGesture()
{
    gestureR = new GestureRecognizer();
    gestureR.SetRecognizableGestures(GestureSettings.Tap);
    gestureR.TappedEvent += myTapEvent;
    gestureR.StartCapturingGestures();
}

private void myTapEvent(InteractionSourceKind source, int tapCount, Ray headRay)
{
    UpdateInfo();
}

int i = 0;
void UpdateInfo()
{
    InitWAStore();
    text.text = ++i + "Count = " + store.anchorCount + " in " + was.Count + "\n";
    string[] ids = store.GetAllIds();
    foreach (string id in ids)
    {
        text.text += id + "\t";
    }
}

public void WorldStoreInstance()
{
    CreateSpheres();
    UpdateInfo();
}

void CreateSpheres()
{
    for (int x = -1; x < 2; x++)
    {
        for (int y = -1; y < 2; y++)
        {
            for (int z = 10; z < 13; z++)
            {
                Transform t = Instantiate(prefabTran, new Vector3(x, y, z), Quaternion.identity);
                t.name = x.ToString() + y.ToString() + z.ToString();
                was.Add(t.GetComponent<WorldAnchor>());
            }
        }
    }
}

void InitWAStore()
{
    for(int i = 0; i < was.Count; i++)
    {
        store.Save(was[i].gameObject.name, was[i]);
    }
}

public void myAsyncDelegate(WorldAnchorStore store){
    this.store = store;
}

}

Tagged:

Answers

  • Options
    stepan_stulovstepan_stulov ✭✭✭
    edited May 2017

    Hey, @ar4ds

    You don't seem to be adding actual WorldAnchor component to your spheres before saving them. Check your "was" list, it must be filled with nulls. Unless the prefab already contains that component, but as far as I know you want to add that component in runtime.

    t.gameObject.AddComponent<WorldAnchor>();

    Building the future of holographic navigation. We're hiring.

Sign In or Register to comment.