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.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Resolved AR Foundation - Camera.WorldToScreenPoint performance

Discussion in 'AR' started by Project-NSX, Jan 19, 2022.

Thread Status:
Not open for further replies.
  1. Project-NSX

    Project-NSX

    Joined:
    Apr 11, 2019
    Posts:
    19
    I want to place an image at a point on a screen space overlay canvas at a point where a 3D object is being rendered.
    To do this, I am using AR foundation's image tracking to place a prefab in the scene where the image is located. I instantiate the png images onto the canvas using the following:
    Declarations:
    public GameObject buttonToSpawn;
    protected Image buttonImage;
    Camera cam;

    Assignment and instantiation in the start method:
    Code (CSharp):
    1. cam = FindObjectOfType<ARSessionOrigin>().camera;
    2. buttonImage = Instantiate(buttonToSpawn, uiCanvas.transform).GetComponent<Image>();
    Finally, I set the image's position on the canvas using the camera's WorldToScreenPoint:
    Code (CSharp):
    1. void LateUpdate()
    2. {
    3.     buttonImage.transform.position = cam.WorldToScreenPoint(transform.position) + new Vector3(0,0,0);
    4. }
    This method works well in a regular 3D scene (getting the camera a little differently of course), with the icons closely matching the points on the model. In the AR scene, the icons lag behind where the model is placed.
    Does anyone know of a solution to improve the performance of tracking a world point to a screen point when using AR Foundation?

    Thanks!
     
  2. Project-NSX

    Project-NSX

    Joined:
    Apr 11, 2019
    Posts:
    19
  3. todds_unity

    todds_unity

    Unity Technologies

    Joined:
    Aug 1, 2018
    Posts:
    324
  4. TheVirtualMunk

    TheVirtualMunk

    Joined:
    Sep 6, 2019
    Posts:
    145

    Looks like similar issue I have;
    https://forum.unity.com/threads/can...-cycle-as-ar-foundation-and-ar-scene.1252692/

    Could you take a look?

    Note; using ArCameraManager.frameReceived does not help.

    Edit; We used to have world space canvases that just scale with the distance to the camera in order to solve this issue, but sometimes we have a case where its really better to use Screen space canvas and move the transform.
     
    Last edited: Mar 15, 2022
Thread Status:
Not open for further replies.