Search Unity

[Solved] How can I disable Point Cloud in AR Foundation ?

Discussion in 'AR' started by DonPeto, Nov 26, 2018.

  1. DonPeto

    DonPeto

    Joined:
    Jul 16, 2018
    Posts:
    2
    Hello,

    I'm using the PlaneDectectionController.cs to enable/disable the planes but I'm looking for a way to hide the feature points too.

    I have tried something like this :
    Code (CSharp):
    1. GameObject.FindWithTag("AROrigin").GetComponent<ARPointCloudManager>().enabled = false;
    But it only freeze the feature point, not hide them.

    I have also tried to find the point cloud's game object with GameObject.Find(), ) to disable or destroy it, but I guess I don't have the good name, I tried with those string : "Point Cloud", "Point cloud", "PointCloud", "Pointcloud".

    Thank you in advance for your assistance.
     
    makaka-org likes this.
  2. DonPeto

    DonPeto

    Joined:
    Jul 16, 2018
    Posts:
    2
    Hi again,

    I solved the problem myself. I guessed right the strings was wrong, so I print every childs' name of the gameobject "AR Session Origin" with this code :

    Code (CSharp):
    1.     public Text uiText;
    2.     GameObject trackables;
    3.  
    4.     private void Update()
    5.     {
    6.         // Get a specific gameobject with its name
    7.         trackables = GameObject.Find("Trackables");
    8.         Debug.Log(trackables.name);
    9.         // To find child in a specific gameobject
    10.         foreach (Transform child in trackables.transform)
    11.         {
    12.             Debug.Log(child.name);
    13.             this.uiText.text += child.name + "\n";
    14.         }
    15.     }
    It's probably dirty but it was working, the name of my point cloud's gameobject was "AR Default Point Cloud(Clone)".
    And after all, I destroyed it with Destroy("AR Default Point Cloud(Clone)").
     
  3. Mal_Duffin

    Mal_Duffin

    Joined:
    Jan 22, 2015
    Posts:
    71
    Hi DonPeto,

    The ARPointCloudManager only exposes the prefab, not the instance they create of the prefab ( the code doesn't keep a reference to the clone ).

    Therefore currently the only way to find it is to do a search for it, like you've done.

    You could also use code similar to below to get the name, in case the prefab is changed later on...

    // Similar to what you did before, to get the ARPointCloudManager
    ARPointCloudManager arCloudManager = arSessionOrigin.GetComponent<ARPointCloudManager>();
    GameObject goPointCloud = arCloudManager.pointCloudPrefab;
    // the prefab might not be set
    if (goPointCloud != null)
    {
    GameObject goClone = GameObject.Find(goPointCloud.name + "(Clone)");
    // check if the prefab instance has been created
    if (goClone != null)
    {
    Destroy(goClone);
    }
    }

    The ARPointCloudManager should really handle removing the particle system internally, hopefully it'll be fixed in the next update.
     
    DonPeto likes this.
  4. fotalik

    fotalik

    Joined:
    Sep 23, 2017
    Posts:
    24
    Hi, any updates?
    I know that i can use
    Code (CSharp):
    1. ARSubsystemManager.depthSubsystem.Stop()
    to stop displaying points and
    Code (CSharp):
    1. ARSubsystemManager.planeSubsystem.Stop()
    for planes.
    It works for planes, because ARPlane has an event
    boundaryChanged whitch is called when plane disabled and i just react on this to fade the plane, but for the points there is nothing like this.
     
  5. fotalik

    fotalik

    Joined:
    Sep 23, 2017
    Posts:
    24
    Oh, i know the better solution. Just need to disable pointCloud to disable all points:
    Code (CSharp):
    1. ARPointCloudManager _pointCloudManager;
    2.  
    3. //...
    4.  
    5. _pointCloudManager.pointCloud.gameObject.SetActive(false);
     
  6. karsnen

    karsnen

    Joined:
    Feb 9, 2014
    Posts:
    65
    Still not working, Anyone with a working solution

    Want to turn ON and OFF the point cloud.
     
  7. V-Jankaitis

    V-Jankaitis

    Joined:
    Nov 12, 2014
    Posts:
    8
    Tested with 2019.1.7 ArFoundation 2.1

    PointCloud.enabled = false; // stops from making new ones

    foreach (var Point in PointCloud.trackables) // removes the existing ones.
    {
    Point.gameObject.SetActive(false);
    }
     
    makaka-org, robfather141 and AlbyDj90 like this.
  8. AlbyDj90

    AlbyDj90

    Joined:
    Feb 7, 2015
    Posts:
    35
    Great! This work well! :D
     
  9. soorya696

    soorya696

    Joined:
    Dec 13, 2018
    Posts:
    71
    Hey I need reference to 'ARPointCloudManager' (I modified the class a little bit). Your code does'nt work. 'goClone' is null. how to fix this?
     
  10. soorya696

    soorya696

    Joined:
    Dec 13, 2018
    Posts:
    71
    Solution for ARFoundation version > 2.2.x

    Code (CSharp):
    1. var points =  SessionOrigin.GetComponent<ARPointCloudManager>().trackables;
    2. foreach(var pts in points)
    3. {
    4.         pts.gameObject.SetActive(false);
    5. }
    6. SessionOrigin.GetComponent<ARPointCloudManager>().enabled = false;
    7.  
     
    Last edited: Nov 25, 2019
    goout88 likes this.
  11. fancyar

    fancyar

    Joined:
    May 5, 2017
    Posts:
    2
    ARPointCloudManager.SetTrackablesActive(false);
    ARPlaneManager.SetTrackablesActive(false);
     
  12. gianakos94

    gianakos94

    Joined:
    Jun 30, 2020
    Posts:
    1
    Hello guys .For disabling points. Just type before start()

    public ARPointCloudManager cloudsPoints;

    and then go there you want to disabling and type

    cloudsPoints.SetTrackablesActive(false);

    just like the @fancyar saying