Configuring the camera

CameraConfig provides details of the camera configuration that ARCore uses to access the camera sensor for a given session. These details include, for example, the targeted capture frame rate and whether a depth sensor is present and used.

When creating a new ARCore session, ARCore uses ARCoreCameraConfigFilter to filter the camera config that best matches the list of available configs. You can use the CameraConfigFilter asset to narrow down the available camera configs for a given device at runtime by filtering based on your app's needs.

Two common use cases for filtering are:

  • Limiting camera capture frame rate to 30 fps. This use case is guaranteed to be supported on all devices. On devices that support 60 fps, ARCore will prioritize camera configs that support that frame rate by default. To filter out all camera configs that support 60 fps, make sure that the Target 60FPS is unchecked, and Target 30FPS option is checked in the ARCoreCameraConfigFilter asset.

  • Prevent ARCore from using the depth sensor. This use case is guaranteed to be supported on all devices. On devices that have a supported depth sensor, ARCore prioritizes camera configs that use the depth sensor. To filter out all camera configs that use the depth sensor, make sure to check Do Not Use in the ARCoreCameraConfigFilter asset.

Using camera config filters in Unity

Prerequisites

This guide is written assuming you have already installed and configured Unity with the ARCore SDK for Unity 1.11.0 or later. If not, see the Unity Quickstart for Android.

Configuring the camera and camera filters in your scene

To configure the camera config in an ARCore Unity project:

  1. Open the HelloAR sample, or open an existing project to follow along with your existing Unity ARCore project.

  2. Select the ARCore Device GameObject in your scene hierarchy.

  3. In the Inspector, double-click the instance of CameraConfigFilter (called DefaultCameraConfigFilter in the sample). Note that all four options are checked by default.

    • To set Target Camera Framerate settings:

      • To target the highest capture frame rate supported by the device, make sure both Target FPS30 and Target FPS60 are checked. The camera capture rate will target 60 fps on devices that support it, and automatically fall back to 30 fps if not. (This is the default setting.)

      • To limit the camera capture rate to 30 fps, check Target FPS30 by itself.

    • To set Depth Sensor Usage settings:

      • To use a depth sensor if the device has it, check both Do Not Use and Require and Use. (This is the default setting.)

      • To prevent ARCore from using a depth sensor regardless of whether the device has it, check Do Not Use, and uncheck Require and Use.

Choosing a specific camera config from the available configs

By default, the ARCore SDK for Unity selects the first available configuration. You can customize the selection logic by implementing and registering your own OnChooseCameraConfigurationDelegate.

public void Awake()
{
    // Register a custom selection function for the callback.
    ARSessionManager.RegisterChooseCameraConfigurationCallback(
        _OnChooseCameraConfigurationDelegate);
}

// Define the new callback function.
private int _OnChooseCameraConfigurationDelegate(
    List<CameraConfig> supportedConfigurations)
{
    // Look through supported camera configurations, and return the
    // index that you want (using 0 as an example).
    return 0;
}