Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

AR-Foundation Proper way to turn off planes after basic placement

Discussion in 'AR' started by sirerr, Nov 24, 2018.

  1. sirerr

    sirerr

    Joined:
    Sep 25, 2016
    Posts:
    5
    Hi I have probably a simple question but I wondering what the best way to do it.

    I am currently working on a game where you place a object where you raycast to the plane. After the object is placed, I got a reference to the planes that were created. How should I turn them off so they aren't seen? Also if I do like simple renderer and collider component off, does it affect them meaning, do they stay in that state until the session is complete?

    Here's what I have for now.

    upload_2018-11-23_21-1-11.png

    Thanks and sorry if this is simple lol

    - sirerr
     
  2. GreeneMachine

    GreeneMachine

    Joined:
    Jul 3, 2015
    Posts:
    126
  3. sirerr

    sirerr

    Joined:
    Sep 25, 2016
    Posts:
    5
    Awesome, thanks very much!
     
    GreeneMachine likes this.
  4. enhawk

    enhawk

    Joined:
    Aug 22, 2013
    Posts:
    833
    Thanks for that link!
     
    GreeneMachine likes this.
  5. noclew

    noclew

    Joined:
    Jun 10, 2016
    Posts:
    7
    Does this disable only the visualizations? Or, does it completely stop plane detection of the session?
     
    unnanego likes this.
  6. unnanego

    unnanego

    Joined:
    May 8, 2018
    Posts:
    191
    Same question
     
  7. tdmowrer

    tdmowrer

    Joined:
    Apr 21, 2017
    Posts:
    605
  8. tdmowrer

    tdmowrer

    Joined:
    Apr 21, 2017
    Posts:
    605
    It only disables the existing ARPlanes' GameObjects; new planes will continue to be detected. If you want to disable plane detection, disable the ARPlaneManager.
     
    unnanego likes this.
  9. Griffo

    Griffo

    Joined:
    Jul 5, 2011
    Posts:
    700
    You say 'planes will continue to be detected' I'm confused dose the first line of code in this function() not disable enable the ARPlaneManager stopping plane detection ?

    Code (CSharp):
    1. public void TogglePlaneDetection()
    2.     {
    3.         m_ARPlaneManager.enabled = !m_ARPlaneManager.enabled;
    4.  
    5.         string planeDetectionMessage = "";
    6.         if (m_ARPlaneManager.enabled)
    7.         {
    8.             planeDetectionMessage = "Disable Plane Detection and Hide Existing";
    9.             SetAllPlanesActive(true);
    10.         }
    11.         else
    12.         {
    13.             planeDetectionMessage = "Enable Plane Detection and Show Existing";
    14.             SetAllPlanesActive(false);
    15.         }
    16.  
    17.         if (togglePlaneDetectionText != null)
    18.             togglePlaneDetectionText.text = planeDetectionMessage;
    19.     }
     
  10. tdmowrer

    tdmowrer

    Joined:
    Apr 21, 2017
    Posts:
    605
    Correct, disabling the ARPlaneManager will disable plane detection. I meant that deactivating the existing ARPlanes will not stop plane detection, i.e., what SetTrackablesActive does.
     
    Rs and Griffo like this.
  11. mistergreen2016

    mistergreen2016

    Joined:
    Dec 4, 2016
    Posts:
    226
    When is it appropriate to turn off plane detection?
     
  12. BuoDev

    BuoDev

    Joined:
    Nov 28, 2018
    Posts:
    45
    When you don't want to detect planes. For example, if you have already detected a plane and placed whatever content you need, you can disable the plane detection - assuming you don't need to place more content.
     
  13. mistergreen2016

    mistergreen2016

    Joined:
    Dec 4, 2016
    Posts:
    226
    Good thing you guys mentioned turning off the detections. Once I placed in models, and detection was running, it would cause memory issues and crash. Turning off detection helped.
     
  14. Hukha

    Hukha

    Joined:
    Aug 12, 2013
    Posts:
    61
    Hi!
    I have just this problem, when i place my model (preloaded and not instantiated) cause lag and freeze for a moment...
    I've tried everything, any suggestions? @tdmowrer
    Thanks a lot!

    EDIT: When i restart the Scene with an AsyncOperation, the model place without issue. I mean, only have this issue when its the first time of the "run"... I dont know why...
     
    Last edited: Dec 3, 2019
  15. mistergreen2016

    mistergreen2016

    Joined:
    Dec 4, 2016
    Posts:
    226
    Thanks for the tip.
     
    Hukha likes this.
  16. Blenderik

    Blenderik

    Joined:
    May 14, 2013
    Posts:
    141
    If I disable PlaneDetection and disable the existing Trackable's gameObjects, does that effect the stability of previously placed ReferencePoints?
     
  17. unnanego

    unnanego

    Joined:
    May 8, 2018
    Posts:
    191
    It doesn't affect the tracking, it only removes the GameObjects, not the actual tracked planes, as I understand
     
  18. Blenderik

    Blenderik

    Joined:
    May 14, 2013
    Posts:
    141
    unnanego: Are you sure? This is what tdmowrer wrote above:
    Correct, disabling the ARPlaneManager will disable plane detection. And setting an entire GO to inactive should disable all its scripts, what's left?
     
    Last edited: Dec 8, 2019
  19. unnanego

    unnanego

    Joined:
    May 8, 2018
    Posts:
    191
    As I understand, the tracking data is not stored in the GameObjects themselves, they are just a representation of the planes in the scene. My guess would be, the ARPlaneManager has the tracking data.
     
  20. Blenderik

    Blenderik

    Joined:
    May 14, 2013
    Posts:
    141
    After giving it some thought, I think the solution is even more simple. The anchorpoints are only important if the environment changes, so your object gets repositioned to the point where foundation puts the plane after obtaining more information. Once you stop tracking, the Unity world does not change anymore and we should be fine either way.
     
  21. auroraDev

    auroraDev

    Joined:
    Nov 22, 2017
    Posts:
    12
    I tried to use Enable/Disable planeTrackable to Toggle Plane Detection, it is okay for normal cases;
    However, i have a case that the plane trackables' poses go wrong because of lost tracking (e.g close app or move fast);

    So, I want to know the way to reset the detection and detect the plane from scratch again.

    I tried to know the ways to do so but can't find any.
    Could anyone tell me?
     
  22. mistergreen2016

    mistergreen2016

    Joined:
    Dec 4, 2016
    Posts:
    226
    You need to save the world map where you close app and load the world map again on open.
    Check the examples on saving world map and I'm sure there's an example on reseting the plane detection.
     
  23. mistergreen2016

    mistergreen2016

    Joined:
    Dec 4, 2016
    Posts:
    226
    If you instantiate the model using the Addressables.InstantiateAsync, you'll see it run smoother.
     
  24. jalajshah

    jalajshah

    Joined:
    Mar 5, 2018
    Posts:
    60
    Hello guys , i am using AR foundation sample toggle plane detection , and PlaceOnPlane.cs sample Cube , but after disable plane detection still i am getting hit pos on plane on touch !!
    is there i am missing something ??
     
  25. unnanego

    unnanego

    Joined:
    May 8, 2018
    Posts:
    191
    to disable plane detection you must disable the ARPlaneManager component
     
  26. kpatulrpatel

    kpatulrpatel

    Joined:
    Mar 13, 2017
    Posts:
    7
    Simply Comment Else Condition
    /*else
    {
    spawnedObject.transform.position = hitPose.position;
    }*/
     
  27. kpatulrpatel

    kpatulrpatel

    Joined:
    Mar 13, 2017
    Posts:
    7
    1) Disable ARPlane Manager Script
    2) SetTrackableActive(false) Also OR
    Deactivate Root Trackables is child of ARCamera. Find Trackables Gamobject and TrackablesGO.SetActive(false);
     
  28. mistergreen2016

    mistergreen2016

    Joined:
    Dec 4, 2016
    Posts:
    226
    Here’s something interesting. I tried to turn off plane detection after loading a serial world map. It messed up the pose driver so the plane shifts out of position. So, I’m stuck leaving it running all the time.
     
  29. unnanego

    unnanego

    Joined:
    May 8, 2018
    Posts:
    191
    Disable it after the worldmap is loaded, maybe?
     
  30. mistergreen2016

    mistergreen2016

    Joined:
    Dec 4, 2016
    Posts:
    226
    Yes, I even disabled a few seconds after the worldmap loaded. I guess the world origin or the pose driver is dependent on the plane detection being on.
     
  31. unnanego

    unnanego

    Joined:
    May 8, 2018
    Posts:
    191
    How exactly are you turning it off? SetTrackableActive(false) only kills the gameobjects, not the planes as trackables inside ARKit, but if you disable ARPlaneManager script, plane tracking will be disabled completely. Which of these two are you doing?
     
  32. mistergreen2016

    mistergreen2016

    Joined:
    Dec 4, 2016
    Posts:
    226
    ARPlaneManager.enable = false;

    I'll try to show you with a video when I can.
     
  33. mistergreen2016

    mistergreen2016

    Joined:
    Dec 4, 2016
    Posts:
    226
    Check out this video

    I load the WorldMap, and then I press the button to turn off ARplaneManager. The plane and Model shift right behind the device so you don't see it.
     
  34. unnanego

    unnanego

    Joined:
    May 8, 2018
    Posts:
    191
    that's exactly what I'm talking about - you shouldn't disable ARPlaneManager, disabling it removes plane tracking completely, you should set the prefab of the plane visualisator to null and do SetTrackablesActive(false) on the ARPlaneManager.
     
    Markus_T likes this.
  35. Markus_T

    Markus_T

    Joined:
    Jan 23, 2014
    Posts:
    8
    This is how I did it, for both stopping the visibility of the planes and for the detection of planes. I called the TrackingToggle() and the PlaneToggle() methods from UI Toggle buttons in Unity.
    I found that if I only turned off SetTrackablesActive but was still finding planes then new planes would still get drawn, that's why I also made the prefab inactive.

    Code (CSharp):
    1.  
    2.     /// <summary>
    3.     /// The not-documented enum mode to detect both horizontal and vertical planes
    4.     /// </summary>
    5.     private PlaneDetectionMode detectEverything = (PlaneDetectionMode)3;
    6.  
    7.  
    8.     /// <summary>
    9.     /// Toggle whether planes are actively being detected or not
    10.     /// </summary>
    11.     public void TrackingToggle()
    12.     {
    13.         detectPlanes = !detectPlanes;
    14.         arPlaneManager.detectionMode = detectPlanes ? detectEverything : PlaneDetectionMode.None;
    15.         Debug.Log("Detection mode is now " + arPlaneManager.detectionMode.ToString());
    16.     }
    17.  
    18.     /// <summary>
    19.     /// Toggle whether found planes are visible or not
    20.     /// </summary>
    21.     public void PlaneToggle()
    22.     {
    23.         planesAreVisible = !planesAreVisible;
    24.         arPlaneManager.SetTrackablesActive(planesAreVisible);
    25.         arPlaneManager.planePrefab.SetActive(planesAreVisible);
    26.     }
    27.  
    28.  
     
    Last edited: Feb 21, 2020
    aldorue likes this.
  36. aldorue

    aldorue

    Joined:
    Nov 25, 2017
    Posts:
    2

    Hi friend!! would you be so kind to share an example project with this solution of yours, thank you very much!
     
  37. jalajshah

    jalajshah

    Joined:
    Mar 5, 2018
    Posts:
    60
    I will share an example project with a tutorial in 5-6 hours.
     
    aldorue likes this.
  38. aldorue

    aldorue

    Joined:
    Nov 25, 2017
    Posts:
    2
    wooww !! the truth would be very useful, thank you very much, we will be waiting, thank you
     
  39. StefanoCecere

    StefanoCecere

    Joined:
    Jun 10, 2011
    Posts:
    210
    did you share that tutorial? thank you!
     
    dradb likes this.
  40. ROBYER1

    ROBYER1

    Joined:
    Oct 9, 2015
    Posts:
    1,449
    arPlaneManager.detectionMode is now obsolete, is there an alternative now?
     
  41. angles20

    angles20

    Joined:
    Feb 2, 2020
    Posts:
    1
    andyb-unity likes this.
  42. ROBYER1

    ROBYER1

    Joined:
    Oct 9, 2015
    Posts:
    1,449
  43. R1PFake

    R1PFake

    Joined:
    Aug 7, 2015
    Posts:
    522
    I tried this method and adjusted some of the methods to the new API changes, but I guess Im missing something, because the visual still shows up.

    First lets check if we talk about the same thing, I want to remove these small "circles" which show the plane ground, this thread is talking about the same thing, correct?

    I have a button which allows you to pick a location so in this state I want the plane / circles to show and in the "play" state I want the circles to be hidden.

    Can someone give me some things about a fully working solution to toggle these circles with the current AR APIs?
     
  44. andyb-unity

    andyb-unity

    Unity Technologies

    Joined:
    Feb 10, 2022
    Posts:
    956
    @R1PFake If you are starting from our sample app, the small spherical visualizations are for point clouds, not planes. If your scene doesn't require point clouds, you can remove the ARPointCloudManager from your XR Origin GameObject. Or set its point cloud prefab to null so that no visuals spawn into the scene.
     
  45. majaroh

    majaroh

    Joined:
    Feb 6, 2022
    Posts:
    2
    Hi,
    could anyhone help me (who is not able to code ...) with this: mobile ios AR unity 2020.36f1
    I want a scene with severeral objects to be instatiated automatically on a detectded plane ( the floor of the exhibition shall be "replaced" with another material slightly above the physical ground, other objects shall be placed in relational height to it).
    - the ARDefaultPlane prefab is apperring always ca 40 cm too high.
    - how can I stop the plane detection after the first plane was detected? (Without any toggle buttons )
    i understand partly the code elements suggested but I don´t know where to change the initial code...