Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice
  2. Ever participated in one our Game Jams? Want pointers on your project? Our Evangelists will be available on Friday to give feedback. Come share your games with us!
    Dismiss Notice

ARFoundation - Switching between front and rear camera

Discussion in 'Handheld AR' started by edee1337, Jan 30, 2019.

  1. edee1337

    edee1337

    Joined:
    Apr 10, 2013
    Posts:
    34
    Hello,

    I'm trying to see if its possible to switch between front and rear cameras while an ARSession is running. Looking at the ARFoundation samples I can't seem to figure out how to explicitly select front or rear camera. Any help would be greatly appreciated!

    Thank you
     
  2. tdmowrer

    tdmowrer

    Unity Technologies

    Joined:
    Apr 21, 2017
    Posts:
    556
    ARFoundation does not let you choose a camera explicitly. ARFoundation provides a platform abstraction to ARCore and ARKit. It is up to these SDKs to choose a hardware camera. Currently, ARCore only uses the rear-facing camera. ARKit will use the front-facing camera for face tracking, but otherwise use the rear-facing camera.

    What are you trying to do? Why do you need to be able to select the camera?
     
  3. edee1337

    edee1337

    Joined:
    Apr 10, 2013
    Posts:
    34
    Thank you for your response! I'm trying to create an AR experience that works with both front and rear cameras (where available). I want to switch between them just like you would with a default camera app.

    I can get this to work by having two separate scenes (one for front cam, one for rear cam) and using SceneManager to switch between the two, but if a more elegant solution is possible that'd be awesome.
     
  4. princetrunks

    princetrunks

    Joined:
    Mar 13, 2015
    Posts:
    3
    Any progress on this? Some clients are asking for AR features to work on both cameras. Would be great to be able to switch them at runtime; especially with ARKit 3's new set of features. Of course; the AR features depending on the camera and devices (as only A12 chips and newer can handle all of ARKit3's features)
     
    MaryamKamel likes this.
  5. distastee

    distastee

    Joined:
    Mar 25, 2014
    Posts:
    43
    You can swap by enabling and disabling different trackable managers of ARKit. For example - if you only turn on the face manager and turn everything else off - it automatically flips to the selfie cam. If you turn on plane tracking - it will automatically flip to the "world" camera.

    So rather than explicitly saying which camera to use - you implicitly make the decision by telling ARKit what kinds of things you want to track and it figures out the rest.
     
    DrSharky and princetrunks like this.
  6. princetrunks

    princetrunks

    Joined:
    Mar 13, 2015
    Posts:
    3
    Oh great. Thank you for that explanation. Indeed, it seems that AR Foundation is picking the camera based on the feature/manager chosen. One other issue seems to be the People Occlusion. The end goal I'm trying to do is have it act as a Segmentation filter on the selfie/front camera; cull out the background behind the user's face/shoulders. So far, switching managers to create such a segmentation filter seems to cause a runtime crash; my guess is because of forcing the hand of this flip. Was worried that maybe People Occlusion or even a more basic segmentation-like filter just wasn't doable on ARKit due to hardware limitations. However, I've been told that ARKit native builds indeed can handle such a thing on the front camera and that it might be a bug of ARFoundation currently (since People Occlusion and all all still so new/in beta).

    I guess in short... hoping to be able to have the feature work on the front camera.
     
    distastee likes this.
  7. edwon

    edwon

    Joined:
    Apr 24, 2011
    Posts:
    201
    I would prefer explicit control of which camera is being used, front or back. For example now in ARKit 3.0 it supports simulaneous planar tracking using the rear camera, while getting data from the front camera at the same time, but it keeps automatically switching to showing the front camera if the face manager is enabled. That's not what I want.
     
  8. Aidan-Wolf

    Aidan-Wolf

    Joined:
    Jan 6, 2014
    Posts:
    56
    Any update on this feature? Would like to be able to switch manually between front and back camera.
     
  9. todds_unity

    todds_unity

    Unity Technologies

    Joined:
    Aug 1, 2018
    Posts:
    147
    We are working on an update that will allow for more explicit selection of the camera.
     
    nilsdr and mariosubspace like this.
  10. nilsdr

    nilsdr

    Joined:
    Oct 24, 2017
    Posts:
    260
    is there a timeline for this feature?
     
    DrSharky likes this.
  11. todds_unity

    todds_unity

    Unity Technologies

    Joined:
    Aug 1, 2018
    Posts:
    147
    AR Foundation packages version 4.0.0-preview.1 are now available and provide for more explicit selection of the camera.
     
  12. nilsdr

    nilsdr

    Joined:
    Oct 24, 2017
    Posts:
    260
    Great, thank you!
     
  13. nilsdr

    nilsdr

    Joined:
    Oct 24, 2017
    Posts:
    260
    Is this supported on iOS? Can't get the front cam image on an iPhone SE or iPhone X. No matter what mode I request, it keeps showing the rear camera.

    Works on Android though.
     
    Jokonut likes this.
  14. nilsdr

    nilsdr

    Joined:
    Oct 24, 2017
    Posts:
    260
    For future readers, this is supported only on iphones with a true depth camera (X and up)
     
    DrSharky likes this.
  15. xzodia

    xzodia

    Joined:
    Jan 24, 2013
    Posts:
    35
    @todds_unity please add support for front camera on older ios devices, I need to be able to select difference cameras for different purposes, one of these purposes might simply be accessing the front camera with no additional requirements, I would like to be able to do this without needing an additional library. Thanks =)
     
  16. Kideokk

    Kideokk

    Joined:
    Jan 18, 2018
    Posts:
    30
    i can't find how to selection of the camera function. i'm using Unity 2019.3.8f1 and AR Foundation4.0 preview. please explain how to select device camera.
     
  17. todds_unity

    todds_unity

    Unity Technologies

    Joined:
    Aug 1, 2018
    Posts:
    147
  18. Elnazt

    Elnazt

    Joined:
    Mar 25, 2020
    Posts:
    2
    Is it possible to run both cameras at the same time, but only display the view of the World camera for example with 3- 4.0.0 version? Or does it have to toggle between the two cameras?
     
  19. DreamPower

    DreamPower

    Joined:
    Apr 2, 2017
    Posts:
    78
    Using ARFoundation 4 preview 3, which camera is being used keeps shifting for me between builds, sometimes facing the world, sometimes facing the user. I'm not changing it, it's set to "World" in the ARCameraManager.
     
  20. DanOrk

    DanOrk

    Joined:
    Nov 27, 2016
    Posts:
    1
  21. waldgeist

    waldgeist

    Joined:
    May 6, 2017
    Posts:
    100
    We need this feature too. Our use case is a social network based on AR, where people can place selfie videos in the world. Switching to the device camera for shooting these videos is too cumbersome and did not work well. So we found a way to record the AR camera instead. But we'd need to switch the camera on the fly. We wouldn't care if world tracking is restarted in this case. Yet we need an on-the-fly flip.
     
  22. waldgeist

    waldgeist

    Joined:
    May 6, 2017
    Posts:
    100
    I tried to set this property to User at runtime, but the rear camera stays active. What might I miss here? I am using Unity 2019.3.15f1 on an iOS device.
     
  23. CKong91

    CKong91

    Joined:
    Sep 11, 2015
    Posts:
    2
    This property will work if you disable current feature/manager script, such as AR Occlussion Manager script.
     
  24. todds_unity

    todds_unity

    Unity Technologies

    Joined:
    Aug 1, 2018
    Posts:
    147
    With AR Foundation 4, we exposed more details on configuring an AR session.

    Not all features are compatible at the same time. In choosing a configuration, the maximum number of features decides which configuration will be active.

    If you build a Unity project with "Development Build" enabled, you will see the set of features and which ones are supported versus not satisfied with the configuration.

    For instance, in this example I am requesting front-facing camera, but I am also requesting "Environment Probes", "Auto-Focus", and "Environment Depth" which are all three rear-facing camera features on my iOS device. The log output contains:
    However, if I disable both "Environment Probes" and "Environment Depth", then the configuration chooser will switch to the front-facing camera. That log output contains:
     
  25. nilsdr

    nilsdr

    Joined:
    Oct 24, 2017
    Posts:
    260
    Hi Todd,

    Thanks for the clarification. In my opinion it is unclear from the docs that the front facing configuration is only available on newer gen iphones with a TrueDepth camera. I think this is causing some confusion.
     
  26. Thomas-Mountainborn

    Thomas-Mountainborn

    Joined:
    Jun 11, 2015
    Posts:
    350
    What is the recommended way of switching cameras at runtime? On ARCore (AR Foundation 4.0.2), I first tried switching using requestedFacingDirection. Then with having 2 cameras in the scene with only one of the camera game objects being active at a time. I also tried moving each camera object to a separate scene and only loading one scene at a time. In all cases, the first switch from world facing to user facing works, but as soon as I switch back, the app crashes with nothing left in the logs.
     
    Last edited: Jun 30, 2020 at 4:40 PM
unityunity