Search Unity

  1. Read here for Unity's latest plans on OpenXR.
    Dismiss Notice

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:
    345
    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

    Unity Technologies

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

    tonOnWu

    Joined:
    Jun 23, 2017
    Posts:
    78
    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

    Unity Technologies

    Joined:
    Apr 21, 2017
    Posts:
    579
    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:
    190
    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:
    78
    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:
    78
    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. tammudo

    tammudo

    Joined:
    Oct 2, 2017
    Posts:
    3
    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!
     
    Psyco92 likes this.
unityunity