I'm working on a Unity AR game in which I'd like to start out using the Face Manager to track Face Pose on the World-Facing Camera. I know for a fact that you can track Face Pose with the World Camera because I've seen it in the ar-foundation-samples project. The one caveat to that is that you have to start in User-Facing Mode first, then press a button to switch to World-Facing mode once the app is running. I'd like for it to start out on World-Facing camera, but every time I try to do this with the Face Manager running, it doesn't work; the camera doesn't come on at all. My question is, why can I switch my face pose tracking from User-Facing to World-Facing with a button click, yet I can't do the same via the Start() or Update() methods?
public class FaceController : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
/*This won't switch the camera*/
camManager.requestedFacingDirection = CameraFacingDirection.World;
}
private void OnEnable()
{
}
public ARCameraManager camManager;
public ARSession aRSession;
bool trigger;
bool trigger2;
public void SwitchMode()
{
/*This will switch the camera when called by a button press */
camManager.requestedFacingDirection = CameraFacingDirection.World;
}
// Update is called once per frame
void Update()
{
}
}
CodePudding user response:
So I discovered that you could only switch cameras AFTER frame 1 had passed. Per derHugo's comment below, I think the best solution is a coroutine as follows:
IEnumerator switchCamera()
{
yield return null;
yield return null;
camManager.requestedFacingDirection = CameraFacingDirection.World;
}