Search Unity

Hide point and plane visuals when game has started?

Discussion in 'AR' started by nathansisler, Aug 6, 2018.

  1. nathansisler

    nathansisler

    Joined:
    Sep 21, 2013
    Posts:
    5
    Just looking for the best/easiest way to do this?
     
  2. rxmarccall

    rxmarccall

    Joined:
    Oct 13, 2011
    Posts:
    353
    The small documentation that there is says: "The generated GameObjects are parented to a special GameObject under the ARSessionOrigin, accessible via ARSessionOrigin.trackablesParent."

    So You could foreach through the children game objects of ARSessionOrigin.trackablesParent and either set the gameobjects inactive or disable their visualizer component.
     
  3. tdmowrer

    tdmowrer

    Joined:
    Apr 21, 2017
    Posts:
    605
  4. tonOnWu

    tonOnWu

    Joined:
    Jun 23, 2017
    Posts:
    83
    Please, can you offer the code you are suggesting? I tried this without success:

    Code (CSharp):
    1. ARPlaneManager aRPlaneManager = GetComponent<ARPlaneManager>();
    2.         aRPlaneManager.enabled = false;
    3.  
    4.         ARPlane[] planesToRemove = FindObjectsOfType<ARPlane>();
    5.         foreach (ARPlane plane in planesToRemove)
    6.         {
    7.             Destroy(plane);
    8.             Debug.Log("PLANES------------ DESTROYING");
    9.         }
    It is called by a button once the plane is visible. What I'm doing wrong?
     
  5. tdmowrer

    tdmowrer

    Joined:
    Apr 21, 2017
    Posts:
    605
    You are only destroying the ARPlane component and leaving the render components. You probably mean to destroy the plane.gameObject.

    You don't need to use FindObjectsOfType<ARPlane>() -- The GetAllPlanes method I mentioned will give them to you without doing any expensive scene traversal.
     
  6. DreamEnder

    DreamEnder

    Joined:
    Apr 12, 2011
    Posts:
    191
    Hi. I have some plane artifacts left over when I switch to non-AR. I use the following code to disable planes:

    Code (CSharp):
    1. ARPlaneManager _ARPlaneManager;
    2.  
    3. ....
    4.  
    5. _ARPlaneManager.enabled = false;
    6. _ARPlaneManager.GetAllPlanes(aRPlanes);
    7.  
    8. foreach (ARPlane pl in aRPlanes)
    9. {
    10.      if (pl != null)
    11.          pl.gameObject.SetActive(false);
    12. }
     
  7. tonOnWu

    tonOnWu

    Joined:
    Jun 23, 2017
    Posts:
    83
    The problem with GetAllPlanes is that it's a void method. If I want it the planes I would have to update that method by hand or create a new version that returns me the List of Planes. I don't mind to do the code, it's easy, but I don't like to do it considering that in very short time (I hope so), we'll going to have an update which will force us to make the fix again. Unless I'm mistaking the GetAllPlane's method. Please, let me know if I'm wrong.
     
  8. tonOnWu

    tonOnWu

    Joined:
    Jun 23, 2017
    Posts:
    83
    Hi guys. I found the solution thanks to other @Edur-Games . Here's what he proposed:

    Code (CSharp):
    1. void DisablePlanes()
    2.     {
    3.         planeManager = GetComponent<ARPlaneManager>();
    4.         List<ARPlane> allPlanes = new List<ARPlane>();
    5.  
    6.         planeManager.GetAllPlanes(allPlanes);
    7.         planeManager.enabled = false;
    8.         foreach (ARPlane plane in allPlanes)
    9.         {
    10.             plane.gameObject.SetActive(false);
    11.         }
    12.     }
    I understood wrong the use of GetAllPlanes. I tried this and worked perfectly. I dare to recommend to Unity to Add this simple and very necessary function somewhere. A lot of people need this.

    Thanks to all of you.
     
    GreeneMachine likes this.
  9. mumudo

    mumudo

    Joined:
    Oct 2, 2017
    Posts:
    4
    I am using 2019.1 with ARFoundation Version 2.2.0 And when I use the GetAllPlanes Method, I receive this error:

    error CS1061: 'ARPlaneManager' does not contain a definition for 'GetAllPlanes' and no accessible extension method 'GetAllPlanes' accepting a first argument of type 'ARPlaneManager' could be found (are you missing a using directive or an assembly reference?)

    I assume the method no longer exists, despite showing up in the ARFoundaiton documentation? Or perhaps I am completely missing something. Any help is greatly appreciated!
     
    rmuk and Psyco92 like this.
  10. TeslaKim

    TeslaKim

    Joined:
    Jun 17, 2020
    Posts:
    1
    jacob_lammert likes this.