Setting camera focus mode for Vuforia ARCamera in Unity

Matti Mäki-Kihniä
2 min readMay 28, 2017

--

This example will cover changing the Vuforia ARCamera prefab’s focus mode in Unity. Information about different camera modes can be found from the Vuforia Developer Library here. This example will go into further detail how to implement the script to change the focus modes.

Depending on your use case the default camera mode might be fine, but if you are reading this then you are most likely looking to change it to something else. As per my experience with a OnePlus3 and a Samsung Galaxy S6 Edge, both running Android Nougat, the default mode does not support autofocus.

In order to change the focus mode a C# script will need to be created and attached to the ARCamera. Click on the ARCamera prefab in the Hierarchy tab, which is by default on the left side of the screen.

The code to change the camera focus mode will be added as a component to the ARCamera. After selecting the ARCamera the Inspector panel should open up on the right side of the screen. There is an “Add Component” button. Click on the button, scroll all the way down to “New Script”, enter “CameraFocusController” as the name and be sure that the selected language is “C Sharp”. Afterwards click on the “Create and Add” button.

A new script file is now created in the ProjectName/Assets/ folder. The script can be located under the Project tab. By double clicking the newly created CameraFocusController file an IDE should open, or you can right click on the file and click “Show in Explorer” and go on from there.

Once you have the file open, add the following lines to it and save it:

Note that if you wish to change the focus mode to something else than continuous, then change the according lines (20 & 28).

--

--