Search Unity

AR Foundation: Continously update position of gameobject

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

Thread Status:
Not open for further replies.
  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:
    45
    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

    Joined:
    Apr 21, 2017
    Posts:
    605
    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
     
  7. Lepisto3D

    Lepisto3D

    Joined:
    Oct 6, 2019
    Posts:
    27
  8. tdmowrer

    tdmowrer

    Joined:
    Apr 21, 2017
    Posts:
    605
    The pose provided by the Tracked Pose Driver (TPD) in a MonoBehaviour Update will be from the previous frame on ARCore and ARKit (though it tends to be more noticeable on ARCore). If you need the pose associated with the current frame, you can subscribe to the Application.onBeforeRender event. The pose is resampled by the TPD just before this event and will give you the correct pose.
     
    henryqng likes this.
  9. Ghus86

    Ghus86

    Joined:
    Oct 24, 2013
    Posts:
    15
    Hi @tdmowrer

    I am trying to use this sample to place objects continously but I am facing an issue in iOS
    every time I point to a table I can't go back to the floor, it seems it gets stuck in a higher plane
    but in android I can move from table to floor and vice versa without a problem

    I am using 2019.2 with ar foundation 2.0.1 do you any ideia why this is happening ?
     
  10. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    Is there any way to get the frame accurate transform in the frameReceived callback? This information is crucial for my computer vision task and cameraObj.transform seem to be off when doing logic in that callback.

    1. Would I get the latest frame and pose if I saved the texture in frameReceived (by for example blitting it to a render texture) and then did all my processing (getting transform.localToWorldMatrix and using the saved texture) in Application.onBeforeRender?

    2. What about the intrinsics matrix, when is this updated? I've seen from my native ARKit apps that the intrinsics can change from frame to frame. It would be great if there was a single callback that provided synchronized values, like the one ARKit provides.
     
    Last edited: Nov 30, 2019
    orangetech likes this.
  11. mohabbadran1998

    mohabbadran1998

    Joined:
    Oct 4, 2019
    Posts:
    3
    Can i place GameObject at each location if i have a list of locations?
     
  12. ejjht

    ejjht

    Joined:
    Jan 22, 2020
    Posts:
    10
    Is arcore more stable than arfoundation? I've seen I'm getting more jittering on arfoundation but I'm not sure
     
  13. todds_unity

    todds_unity

    Joined:
    Aug 1, 2018
    Posts:
    324
    AR Foundation uses ARCore on Android devices.
     
Thread Status:
Not open for further replies.