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.
Where do you find world anchors for Unity?
I recently started developing apps for the HoloLens in Unity and I have not been able to get world anchors to work.
When I try adding a world anchor as a component to a game object I get what appears to be a blank file:
Do I have something installed wrong or do I need to download some custom files or is this how it is supposed to look?
Best Answer
-
OptionsAmerAmer ✭✭✭
Make sure that that its using the camera forward vector and position, not just position vector. You can look in unity to see where its placing the cube before you put it on the lense. Essentially to place infront of you , you do Camera.transform.position + (Camera.transformation.forward * 4). This will set it on the forward vector with 4 meters ahead of your current position.
When I was testing this on my app, I created a debug text that floats somewhere which renders the position as debug text. You can get the worldAnchor from the object but simply getting component cube.GetComponent and then pull its position and output to text somewhere.
Hope this helps. I know its kind of weird that there is no indication that its on, but the best way to know is to get the component and spit out its position. Also in a busy scene you'll notice that things with a world anchor shake a lot less than those without when moving your body and head.
Oh an finally, when you place a world anchor on something, you can't move it unless you remove the anchor and re add it back on. So you want to use anchors on things that don't really move or when they move you take the anchor off and place it back on when done.
http://www.redsprocketstudio.com/
Developer | Check out my new project blog5
Answers
WorldAnchor anchor = gameObject.AddComponent();
Its added dynamically
https://developer.microsoft.com/en-us/windows/holographic/world_anchor_in_unity
http://www.redsprocketstudio.com/
Developer | Check out my new project blog
Thank you very much for the help AmerAmer!
I implemented this on a test cube and I am not sure if it is working. I have the cube 4 metres in front of my main camera and a non-anchored sphere gameobject a metre left of it. When I launch the app the sphere four metres in front and one to the left of me but the cube which the world anchor is nowhere to be seen.
This is the code I had applied to the cube:
using UnityEngine;
using UnityEngine.VR.WSA;
public class CubeAnchor : MonoBehaviour
{
}
Make sure that that its using the camera forward vector and position, not just position vector. You can look in unity to see where its placing the cube before you put it on the lense. Essentially to place infront of you , you do Camera.transform.position + (Camera.transformation.forward * 4). This will set it on the forward vector with 4 meters ahead of your current position.
When I was testing this on my app, I created a debug text that floats somewhere which renders the position as debug text. You can get the worldAnchor from the object but simply getting component cube.GetComponent and then pull its position and output to text somewhere.
Hope this helps. I know its kind of weird that there is no indication that its on, but the best way to know is to get the component and spit out its position. Also in a busy scene you'll notice that things with a world anchor shake a lot less than those without when moving your body and head.
Oh an finally, when you place a world anchor on something, you can't move it unless you remove the anchor and re add it back on. So you want to use anchors on things that don't really move or when they move you take the anchor off and place it back on when done.
http://www.redsprocketstudio.com/
Developer | Check out my new project blog
Thanks again, with your help we were able to finally get world anchors working and we are excited to start learning about special anchors yet. I don't know how long I would have been stuck without your help!
Good luck. Feel free to share your project progress out here. Its cool to see what people are working on.
http://www.redsprocketstudio.com/
Developer | Check out my new project blog