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

Changing screen orientation on IOS via script sometimes result in corrupted view

Discussion in 'iOS and tvOS' started by danUnity, Feb 23, 2021.

  1. danUnity

    danUnity

    Joined:
    Apr 28, 2015
    Posts:
    229
    Hi,

    I'm having an issue where the view becomes corrupted when going from horizontal to vertical view and vice-versa on IOS. It sometimes results in a corrupted view.

    Tested on : Iphone 7 which is on version IOS software version 14.4
    Unity version : 2020.2.3f1
    My packages:
    upload_2021-2-23_17-37-0.png

    The app is working fine on Android but has issues on IOS.

    The issue seems similar to :

    https://issuetracker.unity3d.com/is...es-results-in-corrupted-view-on-ios-10?page=5

    But I'm not sure if it's the same and the error seems old so don't know.

    Anybody could point me in the right direction?

    Thank you!
     
  2. danUnity

    danUnity

    Joined:
    Apr 28, 2015
    Posts:
    229
    Bump!! This is a critical issue for me since it breaks the entire app...

    If you leave the app and just come back to it without quitting it fixes it!

    Am I the only who has that issue??!
     
  3. Petras-Unity

    Petras-Unity

    Unity Technologies

    Joined:
    Oct 7, 2020
    Posts:
    24
    Hey Dan, sounds like you have quite a nasty issue. Could you share the script you are using to change orientation? Also a screenshot of corrupted view would be super helpful as well.
     
  4. danUnity

    danUnity

    Joined:
    Apr 28, 2015
    Posts:
    229
    Hi @Petras-Unity !

    Definitely a pretty bad issue...

    Yes off course, here's the script: (I'm calling SetScreenOrientation with the visual scripting tool Bolt)
    It all works perfectly on Android but not IOS.

    (ISSUE) After going from vertical to landscape:

    upload_2021-2-27_16-40-10.png

    Same thing but half the time it's fine and it looks like this:

    upload_2021-2-27_16-40-56.png

    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. namespace Portal.App {
    4.     [AddComponentMenu("Portal/App/ScreenManager")]
    5.     public class ScreenManager : PortalElement {
    6.  
    7.         public static ScreenManager instance;
    8.  
    9.         /*
    10.             ========================================================================================
    11.             CALLBACKS
    12.             ========================================================================================
    13.         */
    14.  
    15.         protected new void Awake() {
    16.             base.Awake();
    17.  
    18.             if (instance == null) {
    19.                 instance = this;
    20.             } else {
    21.                 Destroy(gameObject);
    22.             }
    23.         }
    24.  
    25.         /*
    26.             ========================================================================================
    27.             FUNCTIONS
    28.             ========================================================================================
    29.         */
    30.  
    31.         public void SetScreenOrientation(ScreenOrientation screenOrientation) {
    32.             Screen.orientation = screenOrientation;
    33.         }
    34.  
    35.         public ScreenOrientation GetScreenOrientation() {
    36.             return Screen.orientation;
    37.         }
    38.  
    39.         public void SetScreenTimeoutToNeverSleep() {
    40.             Screen.sleepTimeout = SleepTimeout.NeverSleep;
    41.         }
    42.  
    43.         public void SetScreenTimeoutToSystemSetting() {
    44.             Screen.sleepTimeout = SleepTimeout.SystemSetting;
    45.         }
    46.  
    47.     }
    48. }
     
  5. Petras-Unity

    Petras-Unity

    Unity Technologies

    Joined:
    Oct 7, 2020
    Posts:
    24
  6. danUnity

    danUnity

    Joined:
    Apr 28, 2015
    Posts:
    229
    Ok will do!