Search Unity

Question Random camera switching... how can it be prevented?

Discussion in 'AR' started by acme3D, May 7, 2023.

  1. acme3D

    acme3D

    Joined:
    Feb 4, 2009
    Posts:
    203
    I have a project that is tracking an image via ARTrackedImageManager to anchor some objects to the scene. Everything worked fine until I changed the image library used for recognition.
    After I changed this, the front device camera kicks in instead of the back camera as it should normally happen.
    No other things were changed between the two compiles. Now, even if I bring back the previous library, still the front camera is used!
    ARCameraManager's facing direction is set to "World", so I really can't understand why this is happening....
    Has anyone experienced this kind of weird behaviour???
     
  2. KyryloKuzyk

    KyryloKuzyk

    Joined:
    Nov 4, 2013
    Posts:
    1,142
    This is not an expected behavior.

    When this happens, try to deploy the app with 'Development build' and look for the log message that starts with 'Using session configuration...' that is coming from XRSessionSubsystem. This log will tell you why this configuration was chosen, what requested features were satisfied, and what not.

    Some configurations take precedence over others, and there is a chance when you switch image library, some other configuration without the Image Tracking feature takes priority. The 'session configuration' log should help you in debugging such cases.
     
    Last edited: May 7, 2023
    andyb-unity likes this.
  3. acme3D

    acme3D

    Joined:
    Feb 4, 2009
    Posts:
    203
    Well.... I now quit the editor, restarted, and normal behaviour (world camera) seems to have resumed now. In any case, nothing, and I repeat nothing, was changed besides the image library used for tracking! Same iOS device, so same hardware capabilities... The new tracking image was even a but smaller than the previous one, so in theory requesting a bit less computational power..
    Besides this, I think that the front camera doesn't support image tracking, so it doesn't make any sense for it to be activated!
     
  4. acme3D

    acme3D

    Joined:
    Feb 4, 2009
    Posts:
    203
    Thanks for the advice! Will do that if this happens again.... It's quite frustrating though, Unity should make a sustem that dosn't decide for itself but sticks with choices made buy developers if they are still compatible with the hardware they're running on!
    Do you think that your asset ARFoundation Remote could somehow help in this? My problem is that the target I'm using is far from the dvt computer, so I have to move anyway with my iOS device far from my development desk anyway...
     
  5. KyryloKuzyk

    KyryloKuzyk

    Joined:
    Nov 4, 2013
    Posts:
    1,142
    Yes, I see how this can be confusing, but it's not Unity's fault. This is how ARCore/ARKit work. These AR providers have a list of supported configurations. At the start of ARSession, you specify what AR features you want to use and the native provider selects the configuration that matches the best in its opinion.
    So in such cases, you should carefully inspect why the native provider selected some specific configuration.

    My plugin will help you to speed up the development process and eliminate the need to build your app after every minor change. You'll be able to run your AR project right in the Editor, see all logs, and inspect the Hierarchy, even put breakpoints in your code.

    But if your image tracking target is not located near your computer, you would have to make sure both your AR device and your work computer stay connected to one wifi network at all times. And you'll have to go back to your computer to see the logs and inspect the Hierarchy.

    But I can suggest a small hack. Take a photo of your image target, open it on your computer, and point your AR device to the computer's screen. The tracking accuracy may be not as good as with the actual image, but at least you'll be at your computer at all times :)
     
    andyb-unity likes this.