Search Unity

Screen resolution when switching scenes

Discussion in 'Scripting' started by shotoutgames, May 29, 2019.

  1. shotoutgames

    shotoutgames

    Joined:
    Dec 29, 2013
    Posts:
    290
    Hi all,
    When I switch scenes Unity defaults to screen res of monitor.
    I am trying to save the resolution of the current scene and us it to set resolution of next scene but no luck.

    Thanks





    Code (CSharp):
    1. IEnumerator LoadYourAsyncScene(int sceneIndex)
    2.     {
    3.  
    4.         SaveWorld sw = SaveManager.instance.saveWorld;
    5.         CurrentResolution.ResWidth = sw.screenResWidth == 0 ? Screen.currentResolution.width : sw.screenResWidth;
    6.         CurrentResolution.ResHeight = sw.screenResHeight == 0 ? Screen.currentResolution.height : sw.screenResHeight;
    7.         CurrentResolution.isFullscreen = sw.isFullScreen;
    8.         Debug.Log("current res " + CurrentResolution.ResWidth + " + " + CurrentResolution.ResHeight);
    9.         Screen.SetResolution(CurrentResolution.ResWidth, CurrentResolution.ResHeight,
    10.             CurrentResolution.isFullscreen);
    11.         Screen.fullScreen = CurrentResolution.isFullscreen;
    12.         yield return new WaitForSeconds(SceneSwitchInterval);
    13.         AsyncOperation asyncOperation = SceneManager.LoadSceneAsync(sceneIndex);
    14.         asyncOperation.allowSceneActivation = false;
    15.  
    16.         // Wait until the asynchronous scene fully loads
    17.  
    18.         while (!asyncOperation.isDone)
    19.         {
    20.             //Output the current progress
    21.             Debug.Log("Loading progress: " + (asyncOperation.progress * 100) + "%");
    22.  
    23.             // Check if the load has finished
    24.             if (asyncOperation.progress >= 0.9f)
    25.             {
    26.                 //Activate the Scene
    27.                 asyncOperation.allowSceneActivation = true;
    28.                 Debug.Log("screen res " + Screen.currentResolution.width + " + " + Screen.currentResolution.height);
    29.  
    30.             }
    31.  
    32.             yield return null;
    33.  
    34.         }
    35.  
    36.     }
     
  2. This shouldn't happen. Are you sure there is no other problems in your code what sets the resolution to a wrong one? False reading from PlayerPrefs or something?
    Because if you're sure that you do not set the resolution upon scene change, the resolution shouldn't be changed. What version of Unity do you use? If you're sure, than submit a bug report.
     
  3. shotoutgames

    shotoutgames

    Joined:
    Dec 29, 2013
    Posts:
    290
    Thanks.
    Yes it turns out the options screen where user can change resolution is changing the resolution in the start method overriding changes in the above code