docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    AR Plane Manager component

    The ARPlaneManager component is a type of trackable manager that detects and tracks flat surfaces in the physical environment. As a trackable manager, it creates GameObjects in your scene for each detected plane.

    AR Plane Manager component
    AR Plane Manager component

    Property Description
    trackablesChanged Invoked when trackables have changed (been added, updated, or removed).
    Plane Prefab If not null, this prefab is instantiated for each detected plane. If the prefab does not contain an AR Plane component, ARPlaneManager will add one.
    Detection Mode The types of planes to detect. There are four options:
    • Nothing: No planes can be detected.
    • Everything: Planes of any alignment can be detected.
    • Horizontal: Horizontally aligned planes can be detected.
    • Vertical: Vertically aligned planes can be detected
    • NotAxisAligned: Planes that are not axis-aligned can be detected.

    Getting started

    Add an AR Plane Manager component to your XR Origin GameObject to enable plane detection in your app. If your scene does not contain an XR Origin GameObject, first follow the Scene setup instructions.

    Whenever your app doesn't need plane detection functionality, disable the AR Plane Manager component to disable plane detection, which can improve app performance. If the user's device does not support plane detection, the AR Plane Manager component will disable itself during OnEnable.

    Respond to detected planes

    While enabled, the AR Plane Manager component will get changes reported by the XRPlaneSubsystem every frame. If any planes were added, updated, or removed, the trackablesChanged event is invoked with the relevant information.

    You can subscribe to trackablesChanged in one of two ways:

    1. Use the Inspector

      a. Create a public method on a MonoBehavior or ScriptableObject with a single parameter of type ARTrackablesChangedEventArgs<ARPlane>, as shown in the example code below:

      public void OnTrackablesChanged(ARTrackablesChangedEventArgs<ARPlane> changes)
      {
          foreach (var plane in changes.added)
          {
              // handle added planes
          }
      
          foreach (var plane in changes.updated)
          {
              // handle updated planes
          }
      
          foreach (var plane in changes.removed)
          {
              // handle removed planes
          }
      }
      

      b. Select your XR Origin GameObject, then Click the Add (+) button on the AR Plane Manger component's trackablesChanged property.

      c. Using the Object picker (⊙), select either a GameObject that contains an instance of your component or an instance of your ScriptableObject, whichever is applicable.

      ARPlaneManager's trackablesChanged event is shown in the Inspector with a subscribed MonoBehavior
      Subscribe to the trackablesChanged event

      d. In the dropdown, select your class name and the name of your method. The method name appears in the Dynamic section of the methods list.

    2. Use C# scripting

      a. Create a public method with a single parameter of type ARTrackablesChangedEventArgs<ARPlane> as shown in step 1a above.

      b. Use the example code below to subscribe to the trackablesChanged event:

      void SubscribeToPlanesChanged()
      {
          // This is inefficient. You should re-use a saved reference instead.
          var manager = Object.FindAnyObjectByType<ARPlaneManager>();
      
          manager.trackablesChanged.AddListener(OnTrackablesChanged);
      }
      

    Visualize planes in the scene

    By default, the AR Plane Manager does not render a textured mesh in the scene when planes are detected. To enable plane visualization, set a prefab as the AR Plane Manager's Plane Prefab.

    The AR Foundation Samples GitHub repository contains a prefab that you could use to get started:

    Prefab Description
    AR Plane Debug Visualizer Visualize plane meshes with a solid color, and optionally visualize additional information such as the plane's trackableId, trackingState, classifications, and normal vector. You can configure the visualization options via the Inspector.

    Custom plane visualizers

    You can also create your own custom plane visualizer for use in your plane prefab. Some common ways to visualize a plane in your scene include using a MeshFilter and MeshRenderer, LineRenderer, or MeshCollider. If your custom visualizer uses one or more of these components, you can add an ARPlaneMeshVisualizer component to your plane prefab to automatically set up the plane mesh data.

    If your custom plane visualizer uses other components to render the plane in the scene, you should subscribe to ARPlane.boundaryChanged to receive updates when the plane boundary changes.

    In This Article
    Back to top
    Copyright © 2024 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)