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?.GetLoadedSubsystem<XRSessionSubsystem>();
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
}
}
}
Note
This code assumes that the app has already initialized XR and that XR Plug-in management settings are set for the target platform
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?.GetLoadedSubsystem<XRCameraSubsystem>();
if (cameraSubsystem.DoesCurrentCameraSupportTorch())
{
cameraSubsystem.requestedCameraTorchMode = XRCameraTorchMode.On;
}
}
Note
This code assumes that the app has already initialized XR and that XR Plug-in management settings are set for the target platform
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.