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

Bug Game may start with incorrect Orientation

Discussion in 'iOS and tvOS' started by kyubuns, Mar 10, 2023.

  1. dorisdabao

    dorisdabao

    Joined:
    Jan 5, 2022
    Posts:
    49

    I guess it is a crash problem. The crash saves the last screen setting result, which will be read at startup, and then set the corresponding screen orientation.
     
  2. AI_NC

    AI_NC

    Joined:
    Aug 10, 2023
    Posts:
    3
    I have a native iOS app which launches Unity iOS 2D games.
    The unity games are opened on first launch in portrait mode filling 50-75% of the screen with the rest of the sceen showing the native iOS app behind that launched it.

    Simply lifting/turning the physical device or setting the app to background and then foreground sets the orientation correct and the issue does not occur again until next time the app is opened from closed state.

    Is this the same issue?

    Unity game is set to autorotation with landscape left/right.
    Native iOS allows portrait mode in login page but the rest of the app is in landscape mode.

    Edit: Using
    Unity 2022.3.6f1
    Device: iPad Air 2 | iOS 15.7.5
     
  3. RaventurnPatrick

    RaventurnPatrick

    Joined:
    Aug 9, 2011
    Posts:
    165
    @AI_NC I think it's best to create a bug report and attach a video + device logs (otherwise we cannot expect a fix)
     
  4. RaventurnPatrick

    RaventurnPatrick

    Joined:
    Aug 9, 2011
    Posts:
    165
    @jperry_oddgames Will you create a new bug report for this problem?
     
  5. AI_NC

    AI_NC

    Joined:
    Aug 10, 2023
    Posts:
    3
    Unity 2022.3.6f1

    I noticed setting default orientation to 'Landscape Right' in Unity Player Settings, will set the orientation to 'Landscape Left' in the generated Xcode project.

    This would mean that the orientation mapping/enum in Unity is not matching with the on for iOS.
    @Alexey, could this have a relation to the orientation issues?
     
  6. Alexey

    Alexey

    Unity Technologies

    Joined:
    May 10, 2010
    Posts:
    1,602
    No, if you read the documentation unity interface orientation enums are "mapped" to apple device orientation not interface orientation (the only difference being indeed landscape left/right)
     
  7. dorisdabao

    dorisdabao

    Joined:
    Jan 5, 2022
    Posts:
    49
    I think the most prominent manifestation of this BUG is:

    Once this bug is triggered,
    Code (CSharp):
    1. Screen.orientation = XXX
    will be invalid,

    Because I have
    Code (CSharp):
    1. Screen.orientation = ScreenOrientation.LandscapeLeft;
    in Start(),

    After entering the game, it will also execute
    Code (CSharp):
    1. Screen.orientation = ScreenOrientation.Portrait
    according to the situation;
     
  8. dorisdabao

    dorisdabao

    Joined:
    Jan 5, 2022
    Posts:
    49
    And the BUG manifests itself as:
    It was in Portrait or AutoRotation when the process was killed last time,
    When entering the game again, the home button of the iPhone is in the Portrait state,
    Even if the game screen and the mobile phone are both in LandscapeLeft at this time,
    At this time, once you switch to the vertical version of the game screen, the vertical version of the game will be displayed under the horizontal screen
     
  9. dorisdabao

    dorisdabao

    Joined:
    Jan 5, 2022
    Posts:
    49
    I removed all obj and code from the scene, created a new Canvas and Button, and added a new script
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5.  
    6. public class NewBehaviourScript : MonoBehaviour
    7. {
    8.     // Start is called before the first frame update
    9.     int orientation = 1;
    10.     void Start()
    11.     {
    12.         Screen.orientation = ScreenOrientation.LandscapeLeft;
    13.         orientation = 1;
    14.     }
    15.  
    16.  
    17.     // Update is called once per frame
    18.     void Update()
    19.     {
    20.      
    21.     }
    22.  
    23.  
    24.     public void ChangeScreenOrientation()
    25.     {
    26.         if(orientation == 3)
    27.         {
    28.             Screen.orientation = ScreenOrientation.Portrait;
    29.             orientation = 2;
    30.         }
    31.         else if(orientation == 2)
    32.         {
    33.             Screen.orientation = ScreenOrientation.LandscapeLeft;
    34.             orientation = 1;
    35.         }
    36.         else
    37.         {
    38.             Screen.autorotateToLandscapeLeft = true;
    39.             Screen.autorotateToLandscapeRight = true;
    40.             Screen.autorotateToPortrait = false;
    41.             Screen.autorotateToPortraitUpsideDown = false;
    42.             Screen.orientation = ScreenOrientation.AutoRotation;
    43.             orientation = 3;
    44.         }
    45.      
    46.     }
    47. }

    Build of 2022.3.6

    environment : IOS16.6 ip14pro

    I opened the game,

    multiple times by pressing the button to switch between horizontal and vertical screens,

    killed the game,

    and quickly reopened it,

    making it easy to reproduce this bug
     
  10. matchalagames

    matchalagames

    Joined:
    Mar 22, 2020
    Posts:
    6
    We get this on android, and we have never been able to reproduce it, but it also seems to stop all of the awake methods from firing in the first scene, essentially breaking the game.
     
  11. dorisdabao

    dorisdabao

    Joined:
    Jan 5, 2022
    Posts:
    49
    Are you sure it's the same bug?I have never seen this bug on Android before,

    It should be said that I have never seen this bug outside of IOS 16,

    Because his need kill process and opened game again
     
    Last edited: Aug 17, 2023
  12. dorisdabao

    dorisdabao

    Joined:
    Jan 5, 2022
    Posts:
    49
    I found a blog:
    iOS16强制屏幕方向失效问题 - 简书 (jianshu.com)

    When the game exits, calling the UnityCleanup function will cause il2cpp to clean up some sub threads. Due to the C # sub threads waiting, failing to clean up after 5 seconds will result in a crash
     

    Attached Files:

    Last edited: Aug 18, 2023
  13. unity_38F5F208A20B1177C02C

    unity_38F5F208A20B1177C02C

    Joined:
    Apr 25, 2022
    Posts:
    5
    Hello dear support. NOT FIXED!!! There's a bug with enabling auto-rotation after entering the game, killing the process, and immediately entering the game again in a physical landscape orientaion. Our game only supports portrait mode. Unity version 2021.3.28f1. iPhone 11 with iOS 16.6 with unlocked auto-rotation option.
     
    Last edited: Aug 25, 2023
  14. unity_mindaugasv

    unity_mindaugasv

    Unity Technologies

    Joined:
    Jun 22, 2023
    Posts:
    3
    Yes, unfortunately, this issue still exists. It appears to be on the Apple side (only on iOS 16) and we have reported it to Apple. Issue tracked here: https://issuetracker.unity3d.com/is...-allowed-when-there-is-another-background-app
     
  15. dorisdabao

    dorisdabao

    Joined:
    Jan 5, 2022
    Posts:
    49
    I used setNeedsUpdateOfSupportedInterfaceOrientations directly in the OC code to perform rotation, and returned the expected direction in all SupportedInterfaceOrientations. This bug will still be triggered, which should indeed be a bug in the IOS16 system