Search Unity

ARfoundation - Camera not in focus

Discussion in 'AR' started by arielfel, Jan 4, 2019.

  1. arielfel

    arielfel

    Joined:
    Mar 19, 2018
    Posts:
    33
    Hey guys and happy new year:)
    Im using unity 2018.3 with ARFoundation 1.0 preview 22, and there is no focus to the camera.
    (the phone is Pixel 2).
    regardless to say this has a heavy impact on the AR performence...

    In the ARFoundation latest release post, there was an update for that autofocus capability
    https://forum.unity.com/threads/arfoundation-1-0-0-preview-22-released.598261/
    but it doesn't seem to achieve it.

    Do we need to set it up somehow? I've tried to look in the camera inspector and components but found nothing.
    thanks for the help!
     
    hopetolive likes this.
  2. tdmowrer

    tdmowrer

    Joined:
    Apr 21, 2017
    Posts:
    605
    Have you seen ARCameraOptions? This works for me on my Pixel.
     
  3. arielfel

    arielfel

    Joined:
    Mar 19, 2018
    Posts:
    33
    Hi, thanks for the quick response.
    sorry, can you elaborate what you mean? it seems that I can't implement your solution(s)... (its probably cause don't have so many years of experience... :)
    Do I need to attach script component to the camera game object? if yes, what should be the code?
     
  4. tdmowrer

    tdmowrer

    Joined:
    Apr 21, 2017
    Posts:
    605
    Attach the ARCameraOptions script to a GameObject in your scene. The inspector UI for this MonoBehaviour includes a setting for the camera focus mode.
     
  5. KISP

    KISP

    Joined:
    Sep 13, 2018
    Posts:
    32
    Where do you get this script? I've updated to the latest version of Unity and Package Manager states that I'm up to date for the ARFoundation/ARKit/ARCore packages, but I'm unable to locate the script in my project.
     
  6. tdmowrer

    tdmowrer

    Joined:
    Apr 21, 2017
    Posts:
    605
    On disk, it is
    <Package Cache>/com.unity.xr.arfoundation/Runtime/AR/ARCameraOptions.cs
    :
    ss.png

    As a component, click the Add Component menu on any GameObject, and search for "ARCameraOptions":
    ss2.png

    The component then has an option to set the focus mode:
    ss3.png
     
    hopetolive and arielfel like this.
  7. KISP

    KISP

    Joined:
    Sep 13, 2018
    Posts:
    32
    Am I doing something wrong? I've navigated to the folder you indicated and not only am I missing the ARCameraOptions script, but I'm missing several other scripts that I can see in your screenshot.

    All of my installation and updating of ARFoundation was performed through the package manager. I just tried removing and re-adding it, but I'm still missing those scripts.
     
  8. tdmowrer

    tdmowrer

    Joined:
    Apr 21, 2017
    Posts:
    605
    What version of ARFoundation do you have?
     
  9. KISP

    KISP

    Joined:
    Sep 13, 2018
    Posts:
    32
    Package Manager says I have 1.0.0 Preview 20. It's the highest option that's available to me.
     
  10. tdmowrer

    tdmowrer

    Joined:
    Apr 21, 2017
    Posts:
    605
    You need ARFoundation 1.0.0-preview.22 to get this feature. You should be able to update using the UI in Window > Package Manager .
     
  11. KISP

    KISP

    Joined:
    Sep 13, 2018
    Posts:
    32
    Package Manager says that 1.0.0-preview 22 is not available. The highest version I can get is 1.0.0-20.
    upload_2019-1-9_9-16-58.png

    I'm using Unity 2018.2.20f1 Pro, which the editor claims is up to date.
     
  12. newguy123

    newguy123

    Joined:
    Aug 22, 2018
    Posts:
    1,248
    Check your unity hub, there should be a version 2018.3.0f2 available
     
  13. tdmowrer

    tdmowrer

    Joined:
    Apr 21, 2017
    Posts:
    605
    As @newguy123 suggests, you also need the latest version of Unity (2018.3) to use ARFoundation preview 22.
     
  14. KISP

    KISP

    Joined:
    Sep 13, 2018
    Posts:
    32
    @newguy123 Thank you. I was able to find Unity 2018.3 by installing the hub as suggested.

    @tdmowrer Thanks for the help, but it appears that ARfoundation preview 22 is a non-starter for me. There seems to be a bug in either the ARFoundation or ARCore package that produces a null reference crash if you start with ARSession disabled and then attempt to reenable it later.

    Specifically, this line crashed:
    Code (CSharp):
    1.    
    2. arSession.enabled = true;
    3.  
    Reverting the packages back to their older versions stopped this crash from occurring.
     
  15. tdmowrer

    tdmowrer

    Joined:
    Apr 21, 2017
    Posts:
    605
    Do you have a callstack for the crash?
     
  16. KISP

    KISP

    Joined:
    Sep 13, 2018
    Posts:
    32
    I do not. I built and ran directly to the Android device.
     
  17. tdmowrer

    tdmowrer

    Joined:
    Apr 21, 2017
    Posts:
    605
    adb logcat -b crash
    should give you a callstack. Also make sure you are on the latest version of ARCore XR Plugin. There was a similar crash bug which was fixed a couple of months ago.
     
  18. KISP

    KISP

    Joined:
    Sep 13, 2018
    Posts:
    32
    Dumb question, but can you point me to a guide on how to use that command?

    I was on the latest version of ARCore when the crash happened. Actually, I suspect that the ARCore package is the problem because I have a version on a mac that builds to ios with the same code and all the updated AR packages and that's working fine.
     
  19. tdmowrer

    tdmowrer

    Joined:
    Apr 21, 2017
    Posts:
    605
    You can read about ADB here. What version of the ARCore package do you have?
     
  20. KISP

    KISP

    Joined:
    Sep 13, 2018
    Posts:
    32
    Running the command didn't produce any output.

    I was running Preview 24 when the problem occurred.
     
  21. tdmowrer

    tdmowrer

    Joined:
    Apr 21, 2017
    Posts:
    605
    Let's back up. If you aren't using logcat, how do you know where it crashed?

    Toggling the session, switching between AR and non-AR enabled scenes, and delayed session enabling are things that we test for regularly. Just to be sure, I've just run that test locally and delayed session enabling works as expected. Do you have any other information you can provide as to how to reproduce this issue or how you are able to know what specific line is problematic?
     
  22. KISP

    KISP

    Joined:
    Sep 13, 2018
    Posts:
    32
    I'm sorry, I've been phrasing this wrong. It's not an actual crash. It's a freeze where the AR doesn't end up turning on and the on-screen UI becomes completely unresponsive. I found that when I commented out only that specific line, the UI wouldn't freeze although there was obviously no AR.

    The only other information I can tell you at this point is that there's a videoplayer and canvas that's created within the same frame.
     
  23. KISP

    KISP

    Joined:
    Sep 13, 2018
    Posts:
    32
    @tdmowrer
    Hello again! Just to let you know, I took another look at my problem again today and was able to figure out what was going on. I had extracted the AndroidManifest xml into the Plugins folder when I was using a earlier version of ARFoundation/ARCore to add some permissions. I wasn't aware that update to the ARCore package raised the required minimum arcore sdk version and so, hadn't changed that value in the extracted manifest. Everything seems to be fine now. Sorry for the trouble!
     
  24. Suwas93

    Suwas93

    Joined:
    Feb 8, 2018
    Posts:
    62
    Just checking in on this camera out of Focus issue. Are there any updates/ Fixes to this issue. I'm having the same issue on pixel devices I'm on Unity 2019.4.8f1 and latest ARFoundation & ARcore
     
  25. tdmowrer

    tdmowrer

    Joined:
    Apr 21, 2017
    Posts:
    605
    On newer Pixel phones (3+ I think), it defaults to a 60Hz configuration which does not support auto focus. See https://developers.google.com/ar/discover/supported-devices for details about your specific device.
     
    Suwas93 likes this.
  26. danUnity

    danUnity

    Joined:
    Apr 28, 2015
    Posts:
    229
    Hi @tdmowrer !

    How are we suppose to support the devices that don't have auto-focus for one reason or another?

    For example the G7ThinQ has a wide lens and only supports a fixed focus.

    Right now, the AR camera manager component is set to Auto focus in my scene and it's blurry with the devices that only supports fixed focus.

    Maybe I'm missing something but what is the right approach to support both fixed and auto focus cameras?

    Thank you
     
  27. tdmowrer

    tdmowrer

    Joined:
    Apr 21, 2017
    Posts:
    605
    Google's list of ARCore supported devices indicates which devices support auto focus. The entry for the LG G7 ThinQ says:
    There is no way to enable auto focus on a device that does not support it, nor is there a way to programmatically detect it (ARCore will report whatever was requested, not what it is actually doing).
     
    Last edited: Jan 6, 2021