Log in or register to post comments

StartAutoFocus returns false

November 22, 2011 - 6:42am #1

I am looking for instructions on how to make StartAutoFocus work. Whenever I call it, it returns false, indicating failure. I have tested on iPad 2, Samsung Galaxy Tab 10.2, and Motorola Olympus MB860. On iOS, autofocus seems to be active regardless. On Android, it is not.

I have the following script attached to my ARCamera:

using UnityEngine;


public class AutoFocus : MonoBehaviour
{
	void Start()
	{
		CameraDeviceBehaviour cameraDeviceBehaviour;
		cameraDeviceBehaviour = GetComponent<CameraDeviceBehaviour>();
		cameraDeviceBehaviour.SetAutoFocusMode(CameraDeviceBehaviour.FocusMode.FOCUS_MODE_MACRO); // also tried FOCUS_MODE_AUTO
		if(cameraDeviceBehaviour.StartAutoFocus())
		{
			Debug.Log("Autofocus started");
		}
		else
		{
			Debug.Log("Autofocus failed to start");
		}
	}
}

I have tried both MODE_DEFAULT and MODE_OPTIMIZE_QUALITY for the camera device mode.

Additionally, I have added the following line to Assets/Plugins/Android/AndroidManifest.xml:

<uses-feature android:name="android.hardware.camera.autofocus" />

Thanks for any suggestions.

Re: StartAutoFocus returns false

November 23, 2011 - 12:39pm #4

Calling StartAutoFocus on a timer worked. Thanks!

Re: StartAutoFocus returns false

November 23, 2011 - 5:48am #3

Note that on Android autofocus is a one-shot event, so calling it on Start isn't sufficient. You'll want to call it on a timer, or in relation to some event (e.g. a user tap).

- Kim

Re: StartAutoFocus returns false

November 22, 2011 - 4:40pm #2

Hello adDispatchARTeam,

Can you try the ImageTargets sample application and tell me if the autofocus menu item works for you? If it does, please check how we are running autofocus.

Thank you,

-Peter

Log in or register to post comments