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

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.

Thanks and sorry if this is simple lol

  • sirerr

Check out the TogglePlanes example here

https://github.com/Unity-Technologies/arfoundation-samples/tree/master/Assets/Scenes/Plane Detection

Script here:

https://github.com/Unity-Technologies/arfoundation-samples/blob/master/Assets/Scripts/PlaneDetectionController.cs

… should help you

3 Likes

Awesome, thanks very much!

1 Like

Thanks for that link!

1 Like

Does this disable only the visualizations? Or, does it completely stop plane detection of the session?

1 Like

Same question

There’s also a utility function for this available on all trackable managers.

3 Likes

It only disables the existing ARPlanes’ GameObjects; new planes will continue to be detected. If you want to disable plane detection, disable the ARPlaneManager.

1 Like

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 ?

public void TogglePlaneDetection()
    {
        m_ARPlaneManager.enabled = !m_ARPlaneManager.enabled;

        string planeDetectionMessage = "";
        if (m_ARPlaneManager.enabled)
        {
            planeDetectionMessage = "Disable Plane Detection and Hide Existing";
            SetAllPlanesActive(true);
        }
        else
        {
            planeDetectionMessage = "Enable Plane Detection and Show Existing";
            SetAllPlanesActive(false);
        }

        if (togglePlaneDetectionText != null)
            togglePlaneDetectionText.text = planeDetectionMessage;
    }

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.

2 Likes

When is it appropriate to turn off plane detection?

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.

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.

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…

Thanks for the tip.

1 Like

If I disable PlaneDetection and disable the existing Trackable’s gameObjects, does that effect the stability of previously placed ReferencePoints?

It doesn’t affect the tracking, it only removes the GameObjects, not the actual tracked planes, as I understand

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?

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.

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.