Google is committed to advancing racial equity for Black communities. See how.

Configuring the camera

To access the supported camera configurations for a given device, AR Foundation's ARCameraManager.GetConfigurations() returns a NativeArray containing multiple instances of XRCameraConfiguration. Each instance of XRCameraConfiguration is an individual camera configuration specifying properties such as depth usage, target capture frame rate, resolution, and texture dimensions.

To expose ARCore-specific properties within XRCameraConfiguration, ARCore Extensions provides XRCameraConfigurationExtension. This extension gives you the following functions for choosing the appropriate camera configuration based on the criteria you want.

Prerequisites

This guide is written assuming you have already downloaded and installed the ARCore Extensions package for ARCore 1.16.0 or later. If not, refer to the Quickstart for ARCore Extensions for Android.

Configuring the camera in your scene

The main steps for configuring the camera for ARCore Extensions are:

  1. Use ARCameraManager with GetConfigurations() to query the list of supported configs on the camera, returning XRCameraConfiguration.

  2. Use any combination of the XRCameraConfigurationExtension functions GetFPSRange, GetDepthSensorUsages, and GetTextureDimensions to find one of the configs that you prefer for a given session based based on the requirements of your app.

  3. Use cameraManager.currentConfiguration to set the current configuration.

// Use ARCameraManager to obtain the camera configurations, and retain the native array of the
// camera in XRCameraConfiguration.
using (var configurations = cameraManager.GetConfigurations(Allocator.Temp))
{
    if (!configurations.IsCreated || (configurations.Length <= 0))
    {
        return;
    }

    // Iterate through the list of returned configs to locate the config you want.
    var desiredConfig = configurations[0];
    for (int i = 1; i < configurations.Length; ++i)
    {
        // This example shows how to choose a config for a given camera that uses the maximum
        // target FPS and texture dimension, and enables the depth sensor if supported.
        if (configurations[i].GetFPSRange().y > desiredConfig.GetFPSRange().y &&
            configurations[i].GetTextureDimensions().x > desiredConfig.GetTextureDimensions().x &&
            configurations[i].GetTextureDimensions().y > desiredConfig.GetTextureDimensions().y &&
            configurations[i].GetDepthSensorUsages() == CameraConfigDepthSensorUsages.RequireAndUse)
        {
            desiredConfig = configurations[i];
        }
    }

    // Set the configuration you want. If it succeeds, the session
    // automatically pauses and resumes to apply the new configuration. If
    // it fails, the session throws an exception.
    if (desiredConfig != cameraManager.currentConfiguration)
    {
        cameraManager.currentConfiguration = desiredConfig;
    }
}