Camera torch mode (flash)
Camera torch mode enables you to activate the device's torch (flashlight) to improve tracking quality in low light conditions.
Check support
Refer to the Optional features support table to learn which provider plug-ins support camera torch mode.
Session configuration
The camera torch may not be available in all session configurations. The following sample code shows you how to list the session configurations that support camera torch mode:
void ListSupportedConfigs()
{
var loader = LoaderUtility.GetActiveLoader();
var sessionSubsystem =
loader != null ? loader.GetLoadedSubsystem<XRSessionSubsystem>() : null;
var configurations =
sessionSubsystem.GetConfigurationDescriptors(Unity.Collections.Allocator.Temp);
for (int i = 0; i < configurations.Length; i++)
{
var config = configurations[i];
if ((config.capabilities & Feature.CameraTorch) != 0)
{
// this configuration supports camera torch
}
}
}
Use the torch
The following sample code shows you how to enable the device's camera torch in a supported session configuration:
void EnableCameraTorch()
{
var loader = LoaderUtility.GetActiveLoader();
var cameraSubsystem = loader != null ? loader.GetLoadedSubsystem<XRCameraSubsystem>() : null;
if (cameraSubsystem.DoesCurrentCameraSupportTorch())
{
cameraSubsystem.requestedCameraTorchMode = XRCameraTorchMode.On;
}
}
Note
The camera torch consumes additional device battery power. Consider warning your users of increased power consumption and giving them an option to disable the torch.