Search Unity

Calling ARSessionOrigin.MakeContentAppearAt() multiple times

Discussion in 'AR' started by dtaddis, Jul 21, 2020.

  1. dtaddis

    dtaddis

    Joined:
    Oct 17, 2019
    Posts:
    20
    Hello,

    We're using ARSessionOrigin to place our content at a user-selected location. During the placement phase, we raycast from the camera, draw a cursor, and when they press "OK", we call:

    MyArSessionOrigin.MakeContentAppearAt(WorldOrigin.transform, MyCursor.transform.position, MyCursor.transform.rotation);

    (WorldOrigin is a GameObject at the world origin. Our levels are authored so that they are centred on the world origin, too.)

    This works well the first time, we even change the scale as well. We set a large (ish) scale on the ARSessionOrigin, around 50, so that our large content gets (apparently) scaled down to roomscale.

    If you want to re-place the AR play area, you can re-enter the mode, and the raycasting and placing the cursor works fine. But when you select "OK", and we call MakeContentAppearAt() for the second time with the same parameters, it is offset from where you selected. It can also be rotated off-axis.

    Am I doing something wrong or is it potentially a bug? Is there a way to "reset" the ARSessionOrigin so I get the nice results seen the first time around?
     
  2. dtaddis

    dtaddis

    Joined:
    Oct 17, 2019
    Posts:
    20
    Okay, I think the issue here may have been that I was raycasting onto a trackable, and subsequent calls to MakeContentAppearAt() didn't account for the fact that there was already an offset and rotation.

    Now when I re-enter AR placement, I call a function to reset the offset, which clears down the transform of the "Trackable" GameObject that gets added, and also the "Content Offset" GameObject that becomes the parent of the camera:

    SessionOrigin.MakeContentAppearAt(WorldOrigin.transform, Vector3.zero, Quaternion.identity);

    // Clear down children
    for (int i = 0; i < SessionOrigin.transform.childCount; i++)
    {
    Transform child = SessionOrigin.transform.GetChild(i);
    child.localPosition = Vector3.zero;
    child.localRotation = Quaternion.identity;
    }

    Perhaps I am mis-using this function.... but this is working for me now.
     
    bostonvaulter likes this.