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
Property | Description |
---|---|
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:
|
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 planesChanged event is invoked with the relevant information.
Subscribe to the planesChanged
event by following the instructions below:
Create a public method on a
MonoBehavior
orScriptableObject
with a single parameter of type ARPlanesChangedEventArgs, as shown in the example code below:public void OnPlanesChanged(ARPlanesChangedEventArgs 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 } }
Use the example code below to subscribe to the
planesChanged
event:void SubscribeToPlanesChanged() { // This is inefficient. You should re-use a saved reference instead. var manager = Object.FindObjectOfType<ARPlaneManager>(); manager.planesChanged += OnPlanesChanged; }
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 two prefabs 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. |
AR Feathered Plane | Visualize plane meshes with a stylized polka dot pattern that fades to become transparent at the edges of the plane's boundary. |
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.