unity-game-engine8thwall-xr

How can I prevent 8th Wall XR from changing my default orientation in Unity?


Every time I build, it changes back to Portrait. I can't find where to disable this automatic change. Is it possible to do?


Solution

  • Go into Player Settings, set the orientation to anything other than Auto Rotation and it won’t be changed.

    You can also change the orientation programmatically. Just make sure it’s set back to a fixed orientation prior to loading your AR Scene. For example, if you want auto-rotate to be enabled in your Non-AR Scenes, you could set Screen.orientation = ScreenOrientation.AutoRotation, and then prior to loading your AR Scene, just set it back to either Portrait or Landscape.

    If you want to get fancy, you could also auto detect the orientation of the device at the time the user presses whatever button that is used to launch the AR scene by first checking Input.deviceOrientation and then setting the Screen.orientation to that.

    Here is an example - Run() function launches your scene (after first checking device orientation and setting the screen orientation based on that):

    void Run(String scene) {
          // Lock orientation to current device orientation prior to loading AR scene 
          switch (Input.deviceOrientation) {
            case DeviceOrientation.Portrait:
              Screen.orientation = ScreenOrientation.Portrait;
              break;
            case DeviceOrientation.PortraitUpsideDown:
              Screen.orientation = ScreenOrientation.PortraitUpsideDown;
              break;;
            case DeviceOrientation.LandscapeLeft:
              Screen.orientation = ScreenOrientation.LandscapeLeft;
              break;;
            case DeviceOrientation.LandscapeRight:
              Screen.orientation = ScreenOrientation.LandscapeRight;
              break;;
            default:
              // if Unknown, just set to Portrait
              Screen.orientation = ScreenOrientation.Portrait;
              break;
          }
        SceneManager.LoadScene(scene);
      }