Search Unity

Bug Camera out of Focus on Android

Discussion in 'AR' started by Suwas93, Sep 30, 2020.

  1. Suwas93

    Suwas93

    Joined:
    Feb 8, 2018
    Posts:
    62
    Camera out of Focus on some Android devices. Is there a way to fix this?
     
  2. Suwas93

    Suwas93

    Joined:
    Feb 8, 2018
    Posts:
    62
    This is happening on Pixel devices.
     
  3. brivero30

    brivero30

    Joined:
    Mar 13, 2020
    Posts:
    4
    I used to have the same problem with my first AR app for Android. This C# code helped me out and it works perfectly for me, just like a normal camera does. Hopefully this works for you too :)

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using Vuforia;
    4.  
    5. public class CameraFocus : MonoBehaviour
    6. {
    7.     void Start()
    8.     {
    9.         var vuforia = VuforiaARController.Instance;
    10.         vuforia.RegisterVuforiaStartedCallback(OnVuforiaStarted);
    11.         vuforia.RegisterOnPauseCallback(OnPaused);
    12.     }
    13.  
    14.     private void OnVuforiaStarted()
    15.     {
    16.         CameraDevice.Instance.SetFocusMode(
    17.             CameraDevice.FocusMode.FOCUS_MODE_CONTINUOUSAUTO);
    18.     }
    19.  
    20.     private void OnPaused(bool paused)
    21.     {
    22.         if (!paused)
    23.         {
    24.  
    25.             CameraDevice.Instance.SetFocusMode(
    26.                CameraDevice.FocusMode.FOCUS_MODE_CONTINUOUSAUTO);
    27.         }
    28.     }
    29. }
     
  4. Suwas93

    Suwas93

    Joined:
    Feb 8, 2018
    Posts:
    62
    I'm sorry. I should have mentioned. This is for AR Foundation
     
  5. KyryloKuzyk

    KyryloKuzyk

    Joined:
    Nov 4, 2013
    Posts:
    1,145
    Suwas93 likes this.