Search Unity

Screen.SetResolution causing black screen or incorrectly sized drawing

Discussion in 'Scripting' started by Michael-Thomas, Oct 10, 2015.

  1. Michael-Thomas

    Michael-Thomas

    Joined:
    Jul 8, 2014
    Posts:
    20
    I seem to be getting some weird behavior when I use the Screen.SetResolution() method to change between fullscreen and windowed mode as well as when changing resolution within windowed mode.

    In particular, when I call it to switch from fullscreen to windowed mode, I get an entirely black window, until I manually drag the window edges to resize it (Note that the black window also occurs if the window is not dynamically sizable, then it's just unrecoverable). There's still sound, so I can hear that the game is running behind the darkness.

    Additionally, sometimes (but not always) when I call SetResolution to switch from windows to fullscreen mode, I get a view where the screen is being drawn at the native resolution of my monitor regardless of the resolution it's set to even though the monitor is set to the correct, lower resolution, resulting in only the top left portion of the game showing up. (Bizarrely the hit boxes for the UI elements on screen appear to align as if the image were correctly sized and thus don't align with the UI elements actually shown)

    Both of these cases feel like there's something I need to call or some event I need to trigger to convince Unity to update itself and notice the change in state. Is there something I can do to force this kind of reset? Or is this a known bug of some kind?

    Thanks in advance.
     
  2. Deleted User

    Deleted User

    Guest

    I was looking into this earlier today and I think there is currently a bug involving screen scaling/resolution. Im not sure if that explains both issues you described but I am pretty sure it is the cause of the first one.

    Also do you happen to know what settings/mode one would have to use to get a fullscreen display of a game running at a lower resolution? To clarify, I mean that my monitor is set to 1080p, and I start the game in fullscreen mode at 720p, but all I get is my game using the top two thirds of the screen, since my screen is obviously still using 1080p. I mean 10 years ago in a game you could select 800/600 and the monitor would refresh and the screen resolution was actually changed! Why the flip cant we do that now!?!?
     
  3. Michael-Thomas

    Michael-Thomas

    Joined:
    Jul 8, 2014
    Posts:
    20
    Here's some more details on the specific cases I have: My monitor is 2560x1600 native. If I start the game at any of the available resolutions it correctly fills the screen (possibly with some edge bars if the aspect ratio is weird, but that's fairly expected).

    - If I then change the resolution while in fullscreen, it changes to that new resolution correctly most of the time. I haven't quite spotted the rule for the exception...
    - If from fullscreen, I switch to windowed mode, it brings up a window of the requested size, but that window is initially filled with black. I can move that window around and it stays black. Immediately upon dragging the edge of the window to resize, even if I put it back exactly where it was before, it now fills in and works fine.
    - If from windowed, I request a new window size, I get the same black-window behavior as above.
    - If from windowed, I request fullscreen, I see only the top left portion of my game (I see more of it the larger the resolution I request).

    @ctrlaltdelete63 - if you're just trying to start up the game fullscreen - I don't believe I've seen this weird behavior for that case - I've tried starting a game from the quality/resolution selection screen with lots of different fullscreen resolutions with no problems on a few different monitors. Any chance you've got a weird aspect ratio resolution? Or is it really the 16:9 720p (i.e. 1280x720)?