Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Resolved ARFoundation hide ARPlanes/Trackables without deactivating/Visualization

Discussion in 'AR' started by Premtey, Feb 5, 2021.

  1. Premtey

    Premtey

    Joined:
    Feb 5, 2021
    Posts:
    6
    Hey guys,

    I'm trying to hide ARPlanes/Trackables so the user can't see them but I don't want them to be deactivated. I found the following method:

    public void SetTrackablesActive(bool active)

    but this method does deactivate the planes/trackables. Therefore when I used this method the ARPlanes were gone but I couldn't also place any objects on the planes cuz there were none.

    I thought of changing the visibility of ARPlanes in the ARPlaneMeshVisualizer class but I'm worried that isn't the right way to go since it's a predefined class.
    By changing the visibility I mean adjust the following code snippet from ARPlaneMeshVisualizer script:

    Code (CSharp):
    1. void SetVisible(bool visible)
    2.  
    3. {
    4.  
    5. var meshRenderer = GetComponent<MeshRenderer>();
    6.  
    7. if (meshRenderer != null)
    8.  
    9. meshRenderer.enabled = visible;
    10.  
    11.  
    12.  
    13. var lineRenderer = GetComponent<LineRenderer>();
    14.  
    15. if (lineRenderer != null)
    16.  
    17. lineRenderer.enabled = visible;
    18.  
    19. }
    I changed meshRenderer.enabled and lineRenderer.enabled to false and it actually worked. But is it also the correct approach or is there an easier way?

    So I would really appreciate if someone could explain me how I could hide ARPlanes without deactivating them.



    Thanks!
     
  2. FrankvHoof

    FrankvHoof

    Joined:
    Nov 3, 2014
    Posts:
    258
    If you want to hide them without disabling, this would indeed be the way to go.
    You can also loop through all children of your Trackables-Parent.
    Potentially you could also get the same result on the GPU-side through use of a custom shader (with a boolean toggle). However this would not reduce the CPU-load for rendering the objects.
     
  3. KyryloKuzyk

    KyryloKuzyk

    Joined:
    Nov 4, 2013
    Posts:
    1,128
    Just remove the ARPlaneManager.planePrefab reference in Inspector.
    Then, you can still use the ARRaycastManager.Raycast() to place your AR objects onto planes.
     
  4. Premtey

    Premtey

    Joined:
    Feb 5, 2021
    Posts:
    6
    Thank you! This solved it!
     
    KyryloKuzyk likes this.
  5. quitebuttery

    quitebuttery

    Joined:
    Mar 12, 2011
    Posts:
    327
    I can't believe how hard it is to do this. A simple visibility override toggle should be part of the API. I think what I'm going to do is when I toggle them off, I'll instantiate a custom invisible plane prefab and copy the plane transforms to them when visibility is disabled. Then just disable the actual arplane.
     
  6. quitebuttery

    quitebuttery

    Joined:
    Mar 12, 2011
    Posts:
    327
    AHA! Here's a way to do it, you have to disable the ARPlaneVisualizer component AS WELL as the mesh and line renderer. Still dumb.