Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

AR Foundation: Continously update position of gameobject

Discussion in 'Handheld AR' started by Conviley, Jan 31, 2019.

  1. Conviley

    Conviley

    Joined:
    Jun 14, 2016
    Posts:
    3
    Hello!

    Me and a friend has been following a tutorial:

    In this tutorial a placment marker is implemented that shows the user where an object will be placed when the screen is tapped. Using the exact same code does not seem to work but when i simply add a ARPlanManager to the ar session origin object it does sort of work but the smoothness seen in the tutorial is not at all achieved. The marker kind of "vibrates" around the center point unless i move my phone very slow. Any ideas?

    First i create the Vector needed
    Code (CSharp):
    1. Vector3 screenCenter = Camera.current.ViewportToScreenPoint(new Vector3(0.5f, 0.5f));
    Then i perform a raycast
    Code (CSharp):
    1. arSessionOrigin.Raycast(screenCenter, hits, TrackableType.Planes);
    then i simply set the position of the marker
    Code (CSharp):
    1. marker.transform.position = hits[0].pose.position
    This is all performed withing update.

    I'm using Unity 2018.3.3f1 and AR Foundation 1.0.0-preview.22 and an OnePlus 6

    -EDIT I changed the Update type of the Tracked Pose Driver of the AR Camera to "Update" and now it's super smooth!
     
    Last edited: Jan 31, 2019
    Dalbino likes this.
  2. BuoDev

    BuoDev

    Joined:
    Nov 28, 2018
    Posts:
    40
    You must be using Android. I've experienced the same issue. I believe it's a mismatch in frame-rates between the camera feed and Unity render rate.

    I haven't been able fix it even by setting
    Code (CSharp):
    1. Application.targetFrameRate = 30;
    or
    Code (CSharp):
    1. Application.targetFrameRate = 60;
    If it seems jittery, Unity is probably rendering at double the frame-rate.
     
  3. Conviley

    Conviley

    Joined:
    Jun 14, 2016
    Posts:
    3
    Yeah jittery is the right word to describe it all and yes i am using android. I've also been unsucessfull with trying the
    Application.targetFrameRate
     
  4. Conviley

    Conviley

    Joined:
    Jun 14, 2016
    Posts:
    3
    I'm happy to say i seem to have found a solution! What you need to do is go into the track pose driver of the ar camera and change the Update Type from "update and before render" to "Update" only. Now it is super smooth! :D
     
  5. tdmowrer

    tdmowrer

    Unity Technologies

    Joined:
    Apr 21, 2017
    Posts:
    490
    The reason for this is because the pose may change between your Update script code and when rendering actually takes place. For XR, we sample the pose as close to rendering as possible to reduce latency. If you are placing objects each frame in your Update script, then the Tracked Pose Driver needs to match, so setting it to "Update" only is one approach.
     
  6. Dioinecail

    Dioinecail

    Joined:
    Jun 1, 2017
    Posts:
    16
    Update didn't work for me, but for some reason "Before Render" worked better, with a very little lag that it is almost unnoticeable