Lock Mobile Camera Orientation in ARFoundation

Hello!

I’m developing a mobile app in Unity using the ARFoundation class and I’m having problems locking the screen orientation. I’ve made the required changes in the Player-> Resolution and Presentation settings, but the behaviour isn’t what I was hoping for. Changing those settings prevents the UI from rotating when the camera is rotated, but the mobile camera feed is still rotating with the device, giving the impression that the orientation isn’t locked and that there’s something wrong with the UI. Is there a way to lock the camera feed in ARFoundation to a specific orientation?

Basically, what I want is to lock the AR camera feed in portrait mode to force the user to use portrait mode.

You just need create a script component and add to AR camera.
In Awake() function, just set orientation by:

Screen.orientation = ScreenOrientation.Portrait;

P/s: You can set any orientation, such as:

  • Portrait: Portrait orientation.
  • PortraitUpsideDown: Portrait orientation, upside down.
  • LandscapeLeft: Landscape orientation, counter-clockwise from the portrait orientation.
  • LandscapeRight: Landscape orientation, clockwise from the portrait orientation.
  • AutoRotation: Auto-rotates the screen as necessary toward any of the enabled orientations.

Can you explain a bit more in depth what it is that you are trying to accomplish?