Hello everyone.

We have decided to phase out the Mixed Reality Forums over the next few months in favor of other ways to connect with us.

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.

The plan between now and the beginning of May is to clean up old, unanswered questions that are no longer relevant. The forums will remain open and usable.

On May 1st we will be locking the forums to new posts and replies. They will remain available for another three months for the purposes of searching them, and then they will be closed altogether on August 1st.

So, where does that leave our awesome community to ask questions? Well, there are a few places we want to engage with you. 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. And always feel free to hit us up on Twitter @MxdRealityDev.

Has anyone ever had success at creating WorldAnchor points?

I have had no success at adding a WorldAnchor component to a GameObject that worked for the HoloLens Emulator. For instance this code snippet:-

    static public GameObject create_sphere(Vector3 pos)
    {
        var m = GameObject.CreatePrimitive(PrimitiveType.Sphere);
        var rigidbody = m.AddComponent<Rigidbody>();
        if (pos!=Vector3.zero)m.transform.position = pos;

        WorldAnchor anchor = null;

        anchor = m.AddComponent<WorldAnchor>();//ALWAYS RETURNS NULL !
        if(anchor !=null)
        {
            addcomment.comment = "added world anchor";
            if(anchor.isLocated)
            {
                //anchor is located
                addcomment.comment = "world anchor is located";
            }
        }
        else
        {
            addcomment.comment = "not added worldanchor";
        }

        rigidbody.velocity = Vector3.zero;
        rigidbody.constraints = RigidbodyConstraints.FreezeAll;
        m.AddComponent<MeshFilter>();
        m.AddComponent<BoxCollider>();
        m.AddComponent<MeshRenderer>();
        return m;
    }

creates spheres on the triangulated background fake mesh like in the following clip:

As you can see the spheres are created but I failed in every instance to create a WorldAnchor associated with each one of them. I have also set up a WorldAnchorStore but of course it does not effect this problem.

I would like to hear from anyone who has had any success in creating WorldAnchors and if there was anything special you had to do.

Best Answer

Answers

  • Alec_HAlec_H ✭✭
    edited July 2016

    @wheelchairman Your assignment of an anchor is setting it to null and is not creating a non null anchor.
    WorldAnchor anchor = gameObject.AddComponent();
    That is how you should be using world anchor as referenced here.

  • AlexDAlexD ✭✭✭

    @wheelchairman please don't open the same question in 3 different places. I've answered the one in Discussion but this is causing unnecessary clutter on the forums.

    Maybe a mod (@Patrick, @ahillier @neerajwadhwa ) can close and consolidate the threads. Thanks.

  • I'll try not to clutter up the forums, I just wanted an answer and it still is elusive. I shall keep to the Discussion Forum for the topic from now on - Sorry

  • AlexDAlexD ✭✭✭

    did you at least see my proper answer in one of your topics ? I think that would help you

  • Sorry AlexD I answered it in the Discussion forum. Even commenting out all the RigidBody component references did not give me a resolution to this problem. I still need to be convinced the WorldAnchor component addtion works properly.

     anchor = m.AddComponent<WorldAnchor>();
    

    This program line does not return and it looks like perhaps there might be a stack or a thread problem with it. Have you an example you could show me where adding this component works? I would be delighted to try it. Thanks for bearing with me I do appreciate it.

Sign In or Register to comment.