Search Unity

full screen toggle not working

Discussion in 'Scripting' started by kelvin-w, Jun 11, 2018.

  1. kelvin-w

    kelvin-w

    Joined:
    Nov 25, 2016
    Posts:
    74
    (version 2018.1.1f1)
    i have a toggle which is being called by a checkbox.

    Code (CSharp):
    1. public void SetFullScreen(bool isFullscreen)
    2.     {
    3.         Screen.fullScreen = isFullscreen;
    4.     }
    when i click the checkbox (after building the game) it doesnt toggle.
    but when i exit fullscreen with alt+Enter and then click the checkbox it enters fullscreen again. but it wont switch back to windowed.

    (the on value change event on the checkbox is selected as dynamic bool)
     
  2. floboc

    floboc

    Joined:
    Oct 31, 2017
    Posts:
    91
    I observed the same issue.
    Did you manage to fix it?
     
  3. kelvin-w

    kelvin-w

    Joined:
    Nov 25, 2016
    Posts:
    74
    not yet. i will let you know if i find a solution!
     
  4. kelvin-w

    kelvin-w

    Joined:
    Nov 25, 2016
    Posts:
    74
    i have been asking around and no one was able to help. could this be a bug in the unity version?
     
  5. deliinteractive

    deliinteractive

    Joined:
    Oct 8, 2014
    Posts:
    25
    Last edited: Jul 3, 2018
    kelvin-w likes this.
  6. kelvin-w

    kelvin-w

    Joined:
    Nov 25, 2016
    Posts:
    74
    thanks alot for your research! i voted for the issue. hopefully this will get fixed soon
     
  7. jaltsu

    jaltsu

    Joined:
    Dec 14, 2017
    Posts:
    5
    I seem to have this in 2018.1.6f1 as well. In Player Settings, I've set Full Screen mode to Windowed, checked Allow Fullscreen Switch and in code I do
    Code (CSharp):
    1. Screen.fullScreenMode = FullScreenMode.Windowed;
    2. Screen.fullScreen = false;
    But still not working.

    Voted on the issue.
     
    Last edited: Jul 13, 2018
  8. Cataclys

    Cataclys

    Joined:
    Jun 12, 2017
    Posts:
    1
    I got the same issue, but to solve that i have done
    Code (CSharp):
    1. Screen.SetResolution(Screen.width, Screen.height, true);
     
  9. Bizquit110

    Bizquit110

    Joined:
    Nov 15, 2016
    Posts:
    12
    Hi, this code worked for me:
    Code (CSharp):
    1.     public static bool FullScreenMode
    2.     {
    3.         get { return Screen.fullScreen; }
    4.         set
    5.         {
    6.             FullScreenMode mode =value
    7.                 ? UnityEngine.FullScreenMode.ExclusiveFullScreen
    8.                 : UnityEngine.FullScreenMode.Windowed;
    9.  
    10.             Screen.fullScreen = value;
    11.             Screen.SetResolution(Screen.width, Screen.height, mode);
    12.         }
    13.     }
     
  10. jaltsu

    jaltsu

    Joined:
    Dec 14, 2017
    Posts:
    5
    kelvin-w likes this.
  11. nia1701

    nia1701

    Joined:
    Jun 8, 2012
    Posts:
    74
    The fix is no longer working on Unity 2018.2.20f1.....
    Anyone else have any ideas?
     
    Magmaw likes this.
  12. manurocker95

    manurocker95

    Joined:
    Jun 14, 2016
    Posts:
    210
    Happening again on 2020.2.7f1 :/
     
  13. angelonit

    angelonit

    Joined:
    Mar 5, 2013
    Posts:
    40
    This code worked for me (notice the use of Screen.currentResolution.width, which gives you the screen current resolution instead of Screen.width, which gives you the window resolution):

    Edited: I set an initial rez value so the windowed mode isn't 0,0 (too small).

    Code (CSharp):
    1.  
    2.         Vector2Int rez = new Vector2Int(1600, 900);
    3.         public void ToggleFullScreen()
    4.         {
    5.             FullScreenMode mode;
    6.             if (Screen.fullScreenMode == FullScreenMode.Windowed)
    7.             {
    8.                 //Save the windowed size
    9.                 rez.y = Screen.height;
    10.                 rez.x = Screen.width;
    11.                 //
    12.                 mode = FullScreenMode.FullScreenWindow;
    13.                 Screen.SetResolution(Screen.currentResolution.width, Screen.currentResolution.height, mode); //This is the important part!
    14.             }
    15.             else
    16.             {
    17.                 mode = FullScreenMode.Windowed;
    18.                 Screen.SetResolution(rez.x, rez.y, mode);
    19.             }
    20.         }
     
    Last edited: Feb 7, 2023
    LethalGenes likes this.