How to switch world/user camera while using AR camera?

Hi

I am creating an application using an AR camera.
Currently, I would like to switch between world and user cameras using a button on the app. To achieve this, I wrote the code below to change the requestedFacingDirection property in ARCameraManager.

However, when I actually ran the code, I was able to confirm that the CameraSwitch() function was called by button operation, but the camera was always displaying the image from the world camera and the image did not switch.

Is there an error in using the requestedFacingDirection property? (If there is any other way to achieve this function, please let me know)

Code:

using UniRx;
using System;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.XR.ARFoundation;
using UnityEngine.XR.ARSubsystems;

public class CameraChangeView : MonoBehaviour
{
    //----------------------------------------------------------------------------------//
    // Member
    //----------------------------------------------------------------------------------//
    [SerializeField] private Button CameraChangeButton;
    [SerializeField] private ARCameraManager arCamera;
    public event Action OnCameraChangeButtonClick; 
    
    //----------------------------------------------------------------------------------//
    // Event
    //----------------------------------------------------------------------------------//
    // Start is called once before the first execution of Update after the MonoBehaviour is created
    void Start()
    {
        CameraChangeButton.onClick.AsObservable().Subscribe( _ => OnButtonClick());
    }

    // Update is called once per frame
    void Update()
    {

    }

    public void CameraSwitch(int cameraNum)
    {
        if(cameraNum == 0)
        {
            arCamera.requestedFacingDirection = CameraFacingDirection.User;
        }
        else
        {
            arCamera.requestedFacingDirection = CameraFacingDirection.World;
        }
    }

    private void OnButtonClick()
    {
        OnCameraChangeButtonClick?.Invoke();
    }
}

Your app’s facing direction is determined by the configuration. Learn more about choosing a configuration here: https://www.youtube.com/watch?v=jBRxY2KnrUs&t=677s. (We also have new docs coming soon about this.)

requestedFacingDirection can be overruled by the configuration chooser depending on which other features your app is trying to use. The video explains configuration choosers and how to write your own.

Our sample app has an example configuration chooser that forces requestedFacingDirection to always be respected, if that’s what your app is trying to do: arfoundation-samples/Assets/Scripts/Runtime/PreferCameraConfigurationChooser.cs at main · Unity-Technologies/arfoundation-samples · GitHub

andyb-unity -san

Thanks for your reply :grinning_face:

I’ll check the video and settings you provided.
If I try it and there are no problems, I’ll close this ticket.