Search Unity

ARfoundation - Camera not in focus

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

  1. arielfel

    arielfel

    Joined:
    Mar 19, 2018
    Posts:
    25
    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!
     
  2. tdmowrer

    tdmowrer

    Unity Technologies

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

    arielfel

    Joined:
    Mar 19, 2018
    Posts:
    25
    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

    Unity Technologies

    Joined:
    Apr 21, 2017
    Posts:
    490
    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:
    29
    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

    Unity Technologies

    Joined:
    Apr 21, 2017
    Posts:
    490
    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
     
    arielfel likes this.
  7. KISP

    KISP

    Joined:
    Sep 13, 2018
    Posts:
    29
    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

    Unity Technologies

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

    KISP

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

    tdmowrer

    Unity Technologies

    Joined:
    Apr 21, 2017
    Posts:
    490
    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:
    29
    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:
    154
    Check your unity hub, there should be a version 2018.3.0f2 available
     
  13. tdmowrer

    tdmowrer

    Unity Technologies

    Joined:
    Apr 21, 2017
    Posts:
    490
    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:
    29
    @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

    Unity Technologies

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

    KISP

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

    tdmowrer

    Unity Technologies

    Joined:
    Apr 21, 2017
    Posts:
    490
    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:
    29
    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

    Unity Technologies

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

    KISP

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

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

    tdmowrer

    Unity Technologies

    Joined:
    Apr 21, 2017
    Posts:
    490
    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:
    29
    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:
    29
    @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!