Search Unity

Bug Setting camera configuration results in a black screen

Discussion in 'AR' started by Petr_Raunigr, Aug 10, 2022.

  1. Petr_Raunigr

    Petr_Raunigr

    Joined:
    Apr 20, 2021
    Posts:
    6
    Hi,

    last week our Android AR app suddenly stopped working properly. The problem is that the AR camera output is a black screen. As we investigated everything we are sure that the cause of our issues is changing camera configuration field in the AR camera manager. We believe that the issue could have been connected to an Android June security update.

    The sample code from our App:
    Code (CSharp):
    1. public ARCameraManager _camera_manager;
    2.  
    3.  
    4. //In constructor
    5. _camera_manager.frameReceived += OnCameraFrameReceived;
    6.  
    7.  
    8. void OnCameraFrameReceived(ARCameraFrameEventArgs eventArgs)
    9. {
    10. ...
    11. _camera_manager.currentConfiguration = configurations[arg_max];
    12. ...
    13. }
    This code was working in a build created with:
    Unity 2020.3.22f1
    ARFoundation 4.1.7
    ARCore 4.1.7
    - We tried to switch to ARFoundation/Core 4.2.3 (we sticked to it in the end) and Unity 2021.3.4f1 with no result.

    We also tried to check AR functionalities using the sample scenes from the AR Foundation package (here) and the same problem happens there. When you launch the "CPU Images" sample scene there is a drop-down list allowing users to switch camera configurations. The default (for our devices) was always the lowest camera configuration (640x320, 30 Hz) and the camera was fine. When we tried to switch to a higher resolution camera configuration the camera stopped working and we could see only a black screen. Switching back to the lowest resolution didn't help.

    What actually did help was a paragraph "Configure the camera during runtime" at the end of this article from Google.

    My questions are:
    1. Are AR Foundation samples not functional simply because of recent changes and these samples were not changed yet to reflect them?
    2. Is the approach from the Google article correct and whole? Or is there anything we missed and there is still a chance that it could not be enough?
    3. Out of curiosity, can someone point out the direct cause of the above code stopped working? This code is basically the same as the one mentioned in the beginning of the Google article + found in the AR Foundation samples.
    4. Can we set a different camera configuration during the runtime or it is now prohibited only to be set during the Awake function?
     
  2. calculmentor

    calculmentor

    Joined:
    Jun 25, 2014
    Posts:
    11
    Hi peter,
    Did you manage to find a solution for this?
    Same pb here…
     
  3. Petr_Raunigr

    Petr_Raunigr

    Joined:
    Apr 20, 2021
    Posts:
    6
    Hi,

    basically, follow the Google article. You need to start listening to the OnChooseXRCameraConfiguration event in Awake and in the method invoked by this event you need to set the camera configuration.


    Code (CSharp):
    1. public void Awake()
    2. {
    3.     //get isntance of the ARCoreExtensions (put this script somewhere in your scene)
    4.     arCoreExtensions.OnChooseXRCameraConfiguration = SelectCameraConfiguration;
    5. }
    6.  
    7. public int SelectCameraConfiguration(List<XRCameraConfiguration> supportedConfigurations)
    8. {
    9.     //go through the whole List and pick a configuration based on your conditions.
    10.     //get ARCameraManager instance
    11.  
    12.     arCameraManagerInstance.currentConfiguration = supportedconfigurations[selected_index];
    13. }
    To be honest, I didn't try to set the configuration more than once during a single runtime so I'm not sure if there is a solution for that. This solution let you at least configure your camera to a more reasonable resolution.
     
  4. calculmentor

    calculmentor

    Joined:
    Jun 25, 2014
    Posts:
    11
    thx peter,
    on my side, all the trouble came from the ARcore on device forcing the update to the new" Google play Services for AR...black screen , black screen, black screeeEEEeeeennnnn!!!
    but, I finally manage to make it work (after 20h of headaque) with
    - unity 2022.1.6f1
    - URP 13.1.8
    -ARcore/foundation/coreXR plugin , all in 5.0.0 pre13

    Just by forcing, in the XRorigin's camera the render mode to "after opaques"...

    upload_2022-8-17_22-13-20.png
    also checked and left unassigned the use "custom material", don't know if it helped but i'm not touching anything !!!
    pffff!
    thx
    .n.
     

    Attached Files:

  5. andyb-unity

    andyb-unity

    Unity Technologies

    Joined:
    Feb 10, 2022
    Posts:
    1,062
    "After opaques" is indeed required for URP in Unity 2022 due to a bug in this version of URP. We're working on several documentation updates and will include this note in a future release, and will likewise update when this bug status is updated.
     
    Last edited: Aug 19, 2022
  6. calculmentor

    calculmentor

    Joined:
    Jun 25, 2014
    Posts:
    11
    Ok Thx but
    Could you give us some guideline about a stable config of version working together?? (ARcore +Unity + URP)
    À git maybe…
    Thx
    .n.
     
  7. calculmentor

    calculmentor

    Joined:
    Jun 25, 2014
    Posts:
    11
    Also, is there a way to avoid conflicts with AR foundation Subsystems when ARcore extensions package ?
    ARcore extensions 1.33 (lastest 14days ago)is still related to the AR subsytem 4.2.3 and I’m all in 5.0pre13..
    Thx in advance
    .n.
     
  8. andyb-unity

    andyb-unity

    Unity Technologies

    Joined:
    Feb 10, 2022
    Posts:
    1,062
    Unfortunately you are unable to use the Google ARCore Extensions with AR Foundation 5.0 until:
    1. AR Foundation 5.0 is released (fully, not as a pre-release package)
    2. Google publishes an update of ARCore Extensions for AR Foundation 5.0
     
    KyryloKuzyk likes this.