Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

Adding a anchor to object rotate the object

Discussion in 'VR' started by justprogramming, Aug 1, 2017.

  1. justprogramming


    Sep 12, 2014
    I am currently trying to add a world anchor to a created object.

    Here is my code:
    1 Object a = UnityEngine.Object.Instantiate(copiedObject);
    2 = "object";
    3 anchorManager.AttachAnchor(a, "obj");

    If I do not have the third line, the object a has the same properties as the original one. However, if I have the third line (adding the anchor), the object a is rotated.

    Why is this happening? And how can I solve it?

    Thanks in advance.
  2. unity_andrewc


    Unity Technologies

    Dec 14, 2015
    In what Microsoft provides us on the back-end, WorldAnchor does have a rotation, and after poking them about it, it is very much intentional - I imagine it has something to do with correcting for a WorldAnchor on the border of a wall and floor thinking it's changing between the two or something.

    To set your own rotation, you'll need to add the WorldAnchor to a parent GameObject (likely one that's completely empty, save for the WorldAnchor component), and then you can set your rotation on the child GameObject for which you care about setting the rotation.

    Keep in mind, though, that WorldAnchors get their position and rotation updated frame to frame. If the WorldAnchor's rotation changes, the system will basically apply that same rotation delta to your child GameObject indirectly, so you may need to set your child GameObject's rotation each frame to account for this.