Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only.

    Please, do not make any changes to your username or email addresses at during this transition time.

    It's still possible to reply to existing private message conversations during the migration, but any new replies you post will be missing after the main migration is complete. We'll do our best to migrate these messages in a follow-up step.

    On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live.

    Read our full announcement for more information and let us know if you have any questions.

Question windowed mode resize affects fullscreen mode layout

Discussion in 'General Graphics' started by tsmspace, Nov 18, 2023.

  1. tsmspace


    Oct 6, 2019
    I have this rudimentary setting for fullscreen to windowed. My game player setting is "windowed" and allow fullscreen. I don't know that much as I'm not a pro, but:

    everything works how I want it to as far as switching from fullscreen to windowed, and the player can resize the window as they please,, however if you go from windowed to full screen after resizing the window, this changes how the image sits on the fullscreen, there's like a border and it doesn't use the whole screen, all depending on exactly the window shape. I have to manually resize the window back full again to go back.

    what am I supposed to do about that?? Basically, I would like to be able to switch from fullscreen to windowed and already the windowed remembers the size , but I don't want it to affect how fullscreen looks, and then secondarily I would like to be able to reset to the default window size with a button, so I also don't know how to do this. I'm not sure if it's actually even a unity thing...


    (( my game is free so if you want to check it out, you can at Ace Racers SP by tsmspace ( or,, it is coming soon to steam so you can search steam for "Ace Racers SP" and it will be available hopefully in a couple of weeks.))
  2. tsmspace


    Oct 6, 2019
    I ended up with a solution, although my solution is a bit extensive. Well,, this solution did end up making for a very desirable behavior, whereby the game will remember if windowed and where, and basically always start back where it was when the player left it. I would still like to hear if there is a better way to do it, as I don't really know, and mine feels a bit hacksmith. (although, I do like that, since I am not a programmer / the worst programmer ever)

    here's my page of code for it. You can see my original code where the lines are commented out. Yes,, quite a bit more extensive now.

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    5. public class FullScreenWindowed : MonoBehaviour
    6. {
    7.     public int windowHeight = 1080;
    8.     public int windowWidth = 1920;
    9.     public int windowx;
    10.     public int windowy;
    11.     public bool isWindowed = false;
    13.     void Start()
    14.     {
    15.         windowx = PlayerPrefs.GetInt("windowx");
    16.         windowy = PlayerPrefs.GetInt("windowy");
    17.         if (PlayerPrefs.GetInt("iswindowed", 0) == 0)
    18.         {
    19.             windowHeight = PlayerPrefs.GetInt("windowheight", 1080);
    20.             windowWidth = PlayerPrefs.GetInt("windowwidth", 1920);
    21.             isWindowed = false;
    22.             SetFullScreen();
    23.         }
    24.         else
    25.         {
    26.             windowHeight = Screen.height;
    27.             windowWidth = Screen.width;
    28.             isWindowed = true;
    29.             Screen.MoveMainWindowTo(Screen.mainWindowDisplayInfo, new Vector2Int(windowx, windowy));
    30.         }
    31.     }
    33.     void Update()
    34.     {
    35.         if (isWindowed)
    36.         {
    37.             windowx = Screen.mainWindowPosition.x;
    38.             windowy = Screen.mainWindowPosition.y;
    39.             PlayerPrefs.SetInt("windowx", windowx);
    40.             PlayerPrefs.SetInt("windowy", windowy);
    41.         }
    42.     }
    43.     public void SetFullScreen()
    44.     {
    45.         if (isWindowed)
    46.         {
    47.             isWindowed = false;
    48.             PlayerPrefs.SetInt("iswindowed", 0);
    49.             windowHeight = Screen.height;
    50.             windowWidth = Screen.width;
    51.             PlayerPrefs.SetInt("windowheight", windowHeight);
    52.             PlayerPrefs.SetInt("windowwidth", windowWidth);
    53.             windowx = Screen.mainWindowPosition.x;
    54.             windowy = Screen.mainWindowPosition.y;
    55.             PlayerPrefs.SetInt("windowx", windowx);
    56.             PlayerPrefs.SetInt("windowy", windowy);
    57.             //Screen.fullScreen = true;
    58.             Screen.SetResolution(1920, 1080, FullScreenMode.ExclusiveFullScreen);
    59.         }
    60.     }
    61.     public void SetWindowed()
    62.     {
    63.         if (!isWindowed)
    64.         {
    65.             isWindowed = true;
    66.             PlayerPrefs.SetInt("iswindowed", 1);
    67.             Screen.MoveMainWindowTo(Screen.mainWindowDisplayInfo, new Vector2Int(windowx, windowy));
    68.             Screen.SetResolution(windowWidth, windowHeight, FullScreenMode.Windowed);
    69.             //Screen.fullScreenMode = FullScreenMode.Windowed;
    70.         }
    71.     }
    72. }