Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Dropdown for Screen.fullScreenMode doesn't save/load with PlayerPrefs

Discussion in 'Scripting' started by ObsidianSpire, Mar 20, 2020.

  1. ObsidianSpire

    ObsidianSpire

    Joined:
    Sep 13, 2013
    Posts:
    48
    in Start() I get the int from PlayerPrefs, set the dropdown value, and then call SetResolution() which calls SetFullscreenMode().

    Code (CSharp):
    1. int selectedFullscreenMode = PlayerPrefs.GetInt("SelectedFullscreenMode", 0);
    2. fsDropdown.value = selectedFullscreenMode;  //fullscreenDropdown value - 0 (Fullscreen Window), 1 (Exclusive Fullscreen)
    3. //2 (Maximized Window [not supported on Windows]), 3 (Windowed)
    4.  
    5. SetResolution();
    6.  
    7. public void SetFullscreenMode()
    8.     {
    9.         if(fsDropdown.options[fsDropdown.value].text == "Fullscreen Window")
    10.         {
    11.             Screen.fullScreenMode = FullScreenMode.FullScreenWindow;
    12.             Debug.Log("Fullscreen Window");
    13.             Screen.fullScreen = true;
    14.             PlayerPrefs.SetInt("SelectedFullscreenMode", 0);
    15.         }
    16.         else if(fsDropdown.options[fsDropdown.value].text == "Exclusive Fullscreen")
    17.         {
    18.             Screen.fullScreenMode = FullScreenMode.ExclusiveFullScreen;
    19.             Debug.Log("Exclusive Fullscreen");
    20.             Screen.fullScreen = true;
    21.             PlayerPrefs.SetInt("SelectedFullscreenMode", 1);
    22.         }
    23.         else if (fsDropdown.options[fsDropdown.value].text == "Maximized Window")
    24.         {
    25.             Screen.fullScreenMode = FullScreenMode.MaximizedWindow;
    26.             Debug.Log("Maximized Window");
    27.             //Screen.fullScreen = false;
    28.             PlayerPrefs.SetInt("SelectedFullscreenMode", 2);
    29.         }
    30.         else if (fsDropdown.options[fsDropdown.value].text == "Windowed")
    31.         {
    32.             Screen.fullScreenMode = FullScreenMode.Windowed;
    33.             Debug.Log("Windowed");
    34.             //Screen.fullScreen = false;
    35.             PlayerPrefs.SetInt("SelectedFullscreenMode", 3);
    36.         }
    37.     }
    38.  
    39.  
    40. public void SetResolution()
    41.     {
    42.         //Debug.LogError(resDropdown.value);
    43.         Resolution res = resolutions[resDropdown.value + 1];
    44.         Screen.SetResolution(res.width, res.height, Screen.fullScreen);
    45.         SetFullscreenMode();  //where it is called from Start
    46.         PlayerPrefs.SetInt("CurrentResolution", resDropdown.value);
    47.     }

    Is there something about fullScreenMode that I might be missing or is this a bug with Unity (using 2019.2.19f1) of some kind? I defaulted the dropdown value to Exclusive mode and now it always starts there despite Debug.Logs showing that it changes when selected in the build.

    Thanks for any help.
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,519
    I haven't tinkered with this specifically, but it's possible you need to wait one frame and then do the above actions. Just speculating that perhaps on its first frame Unity is still setting stuff up related to the presentation surface.
     
  3. ObsidianSpire

    ObsidianSpire

    Joined:
    Sep 13, 2013
    Posts:
    48
    Thought it might be related so I called start again after 0.05f seconds. No change in behavior.


    Code (CSharp):
    1. public float timer = 0.05f;
    2. public float timerVal = 0.05f;
    3. public bool checkStart = false;
    4.  
    5. void Update()
    6.     {
    7.         if (checkStart && rePlayer.GetButtonDown("Pause"))
    8.         {
    9.             PauseGame();
    10.         }
    11.         timer -= Time.deltaTime;
    12.         if(timer <= 0.0f && ! checkStart)
    13.         {
    14.             timer = timerVal;
    15.             Setup();  //renamed start to check
    16.             checkStart = true;
    17.             Debug.Log("Start recalled.");
    18.         }
    19.     }
     
  4. ObsidianSpire

    ObsidianSpire

    Joined:
    Sep 13, 2013
    Posts:
    48