Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Disable screen rotation in 2017

Discussion in 'Android' started by Meltdown, May 9, 2017.

  1. Meltdown

    Meltdown

    Joined:
    Oct 13, 2010
    Posts:
    5,797
    I've tried about 10 ways of disabling screen rotation based on previous answers and forum posts, but nothing works on Android 7.0

    I currently have this in my manifest...

    Code (CSharp):
    1. <activity android:name="com.unity3d.player.UnityPlayerActivity" android:label="@string/app_name" android:screenOrientation="landscape" android:configChanges="keyboardHidden|orientation|screenSize">
    But still the screen rotates. I want to lock it to landscape.

    Any ideas?

    Thanks
     
  2. florianpenzkofer

    florianpenzkofer

    Unity Technologies

    Joined:
    Sep 2, 2014
    Posts:
    479
    In Unity you would do that in PlayerSettings->Resolution and Presentation.
    Please let us know if there are any problems with that.
     
  3. Meltdown

    Meltdown

    Joined:
    Oct 13, 2010
    Posts:
    5,797
    And which exact option in Resolution and Presentation would that be?
    Setting it to Landscape Left does not lock the rotation on Android 7
     
  4. florianpenzkofer

    florianpenzkofer

    Unity Technologies

    Joined:
    Sep 2, 2014
    Posts:
    479
    Setting the "Default Orientation" to anything but "Auto Rotation" should work.
    "Auto Rotation" + checking only a single box in the list of "Allowed Orientations for Auto Rotation" should also work.

    Worked for me on the Google Pixel (Unity version is roughly current 2017.1 beta). If it doesn't work then please report a bug so that our QA can have a look.
     
  5. Meltdown

    Meltdown

    Joined:
    Oct 13, 2010
    Posts:
    5,797
    I'm using Unity 5.6.0p2, is that allowed orientations feature new in Unity 2017 only?
    I don't see it in 5.6.0p2.
     
  6. Korigoth

    Korigoth

    Joined:
    Jul 21, 2014
    Posts:
    105
    it's there in 5.5 so i guess it's there too in 5.6 :)
     
  7. Meltdown

    Meltdown

    Joined:
    Oct 13, 2010
    Posts:
    5,797
    Ok I see now, if I set to Auto Rotation, it appears. Dumb UX on Unity's part to be honest. You'd think if you select Landscape, it will force landscape.
     
  8. florianpenzkofer

    florianpenzkofer

    Unity Technologies

    Joined:
    Sep 2, 2014
    Posts:
    479
    That should work. As I said earlier you basically have two options to achieve this.
     
  9. John3D

    John3D

    Joined:
    Mar 7, 2014
    Posts:
    441
    In Unity2017.1 I only see a dropdown menu and I can select only 1 option. How can I select both Landscape options?
    Thanks!
     
  10. JuliusM

    JuliusM

    Unity Technologies

    Joined:
    Apr 17, 2013
    Posts:
    824
    Choose "Auto Rotation", then "Allowed Orientations for Auto Rotation" will appear. Select both "Landscape Right" and "Landscape Left" checkboxes there.
     
    flovo543 and John3D like this.
  11. Jichaels

    Jichaels

    Joined:
    Dec 27, 2018
    Posts:
    237
    Necroing this because my issue is similar, I want to ENABLE autorotation, but for the sake of me it doesn't work.

    I have Default orientation set as "Auto Rotation" and checked both landscape, but it does not rotate...

    I'm on URP, is this overriden by something or I don't know ? What's going on ?

    upload_2020-2-27_17-5-25.png
     
  12. JuliusM

    JuliusM

    Unity Technologies

    Joined:
    Apr 17, 2013
    Posts:
    824
    Which Unity version do you use? On which device have you tried this? Have you tried on multiple devices? Try a new empty project, maybe you have a custom manifest in your project or some plugins modify the behavior.
     
  13. Jichaels

    Jichaels

    Joined:
    Dec 27, 2018
    Posts:
    237
    2020.1.24 (will try on 25 as it released, I know it's alpha)
    OnePlus 6 with OxygenOS 10.3.1 / Android 10
    Only have one device, but I sent the game to a friend and he couldn't aswell
    I never touched anything in the manifest (I'm never doing mobile, wanted to try and experiment a bit) and have no plugins on the project.

    Is URP, new input system or some Unity package known to introduce this behaviour ? If not, is there any other settings than the ones I posted above in the PlayerSettings ?
     
  14. Jichaels

    Jichaels

    Joined:
    Dec 27, 2018
    Posts:
    237
    Doesn't work on .25 either
     
  15. JuliusM

    JuliusM

    Unity Technologies

    Joined:
    Apr 17, 2013
    Posts:
    824
    I am not aware of any packages that would introduce this behavior. The only things that come to my mind are:
    1. Maybe you are setting a fixed orientation in your scripts? For example setting Screen.orientation to landscape right in the script would overwrite the autorotation setting in the editor and it wouldn't rotate anymore.
    2. Maybe the autorotation is disabled in the Android OS settings on the device? That setting was not preventing rotation changes before, but I've heard recently, that on some Samsung devices with Android 10 disabling OS autorotation would prevent Unity to autorotate as well. Maybe that is happening on your device as well?
     
  16. Jichaels

    Jichaels

    Joined:
    Dec 27, 2018
    Posts:
    237
    1. Nope, not touching anything in that. I even tried to manually allow Screen.autorotateToLandscapeLeft/Right to true in script, but it doesn't do anything either.

    2. I indeed have a button to toggle autorotation, but it is set to true, and other apps are rotating normally
     
  17. JuliusM

    JuliusM

    Unity Technologies

    Joined:
    Apr 17, 2013
    Posts:
    824
    Well, the easiest thing to try is to create a new empty project, set autorotation to the same values as in another project and check if it autorotates or not. If it does - then there must be something with the configuration of the project. If it does not rotate even with an empty project - please report a bug.
     
  18. Jichaels

    Jichaels

    Joined:
    Dec 27, 2018
    Posts:
    237
    But this is what I did, I created and built this projet within the same day (basic flappy bird-like) just to experiment. I'll try with default package, and with the ones I have and report
     
  19. Jichaels

    Jichaels

    Joined:
    Dec 27, 2018
    Posts:
    237
    Update :

    On a default project (URP template), without touching anything else than unchecking both Portrait in AutoRotation, it does rotate on my phone.

    I though about what could cause the issue, because I had a similar thing happening for desktop. Some datas from PlayerPrefs regarding screen position / size where saved in PlayerPrefs and set back without any code from my side.

    I may (I don't remember) have built the app without autorotation or something, could it have saved that data and fetch that instead of what I now set in the PlayerSettings ? If so, how could I reset that ? (tried uninstalling the app, clearing data AND cache, but still no rotation).

    In the meantime, I'll try to update the packages to match and see if it stop the rotation
     
  20. Jichaels

    Jichaels

    Joined:
    Dec 27, 2018
    Posts:
    237
    New update, found the problem.

    Installing the new input system does prevent the rotation. I'll try to post there to get a solution
     
    JuliusM likes this.