Default Screen Dimensions Being Ignored After Build

In my PlayerSettings I have the Default Screen Width set to 1280 and the Default Screen height set to 720. When I build the project the player launches in 1920x1080 and sets the width/height registry value to 1920x1080.

This was working all fine and dandy before updating to Unity 2017.2 (wow!).

It’s also worth nothing that my builds are also creating a 22MB ‘UnityPlayer.dll’ file on my Desktop which was not happening before updating to 2017.2 and I’m thinking this may have something to do with it.

Any suggestions?

3 Likes

The build/player stores the last used screen size in the Windows Registry and reads/restores it when the game starts. Once these values are written to the Windows Registry, “Default Screen Width/Height” have no effect anymore, because Unity reads it from the Registry instead.

To test modified Default Screen settings, it seems you need to remove the Windows Registry key before starting the game. That is at least the only workaround I found to make that work.

These keys are located under:
Computer\HKEY_CURRENT_USER\Software\<Company Name>\<Product Name>\

Where <Company Name> and <Product Name> must be replaced with whatever you entered for those in the PlayerSettings.

The keys you want to remove are:

  • Screenmanager Resolution Height
  • Screenmanager Resolution Width
  • Screenmanager Is Fullscreen mode
21 Likes

THANK YOU, THANK YOU, THANK YOU, THANK YOU!!!

3 Likes

Hi,

Thanks for the tip. The problem is still present in 2019.1.0f2.

I didn’t delete the values you mentioned, I just modified the resolutions Height and Width with the correct values and my game displays at it should now. :slight_smile:

1 Like

Has this been reported?

This is kind of by design. You want the game to remember the last resolution it was run in. The player setting only specifies the default resolution - the resolution the game will start in. When you play any game, you usually want to adjust that resolution to either match your monitor resolution or reduce it if your GPU is weak. It would suck if you had to do it every time you started the game on your PC.

1 Like

You’re right, I want my game to play full screen 600 x 900 like I built if, not full screen native resolution. Right now it doesn’t because the last resolution stored is 1920 x 1080 and setting the new resolution 900 x 600 is not recorded. If you find this normal, okay, I guess I’ll have to do with it.

1 Like

You can always change the resolution to the one you want at startup in your code if you wish. However keep in mind that forcing a specific resolution will make your game look really badly on monitors with a different aspect ratio.

If the aspect ratio does not match, Unity’s DX11 and OGL implementations fix that via pillar- and letter-boxing:
https://discussions.unity.com/t/735010

Anyway, the fact that the registry key is never modified by the new resolution you want to choose for your game is an anomaly that needs to be fixed.

Unfortunately, I suspect that reporting that as a bug will be useless and nobody will listen.

How do I change the resolution at startup in code? Thank you.

I think I found that in a blog post when I googled around for letterboxing. Attach this script to your camera:

 void Start()
    {
        float targetaspect = 16.0f / 9.0f;
        float windowaspect = (float)Screen.width / (float)Screen.height;
        float scaleheight = windowaspect / targetaspect;

        Camera camera = GetComponent<Camera>();

        // if scaled height is less than current height, add letterbox
        if (scaleheight < 1.0f)
        {
            Rect rect = camera.rect;
            rect.width = 1.0f;
            rect.height = scaleheight;
            rect.x = 0;
            rect.y = (1.0f - scaleheight) / 2.0f;
            camera.rect = rect;
        }
        else
        { // else add pillarbox
            float scalewidth = 1.0f / scaleheight;
            Rect rect = camera.rect;
            rect.width = scalewidth;
            rect.height = 1.0f;
            rect.x = (1.0f - scalewidth) / 2.0f;
            rect.y = 0;
            camera.rect = rect;
        }
    }

Depending on the type of canvas you use, you might have to do some scaling there as well.

1 Like

Thank you! I’m going to try it. :slight_smile:

Edit: I just tried it in a game that doesn’t require pillarboxes just to see how it works and it does work very well. No need to modify the resolution in the Player settings. New aspect ratio 1:1.

I owe you! :slight_smile:

Well, as I said, that player setting denotes the default resolution. It’s not “this is the resolution the game must run in” setting.

While the editor could modify the registry for your current PC, it falls apart as soon as you copy your game to another machine.

It does, but what kind of gamer wants his monitor space unused? Imagine you force 4:3 aspect ratio. People with ultra wide monitors will have over 40% of their monitor real estate rendered useless.

Hi again, :slight_smile:

I slightly modified the script so that the ratio can be chosen in the Inspector. Here is the result:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class GameRatioAspect : MonoBehaviour
{
    //ratioAspect: 1 = 1.0 / 1.0 ; 1.77 = 16.0 / 9.00 ; 1.33 = 4.0 / 3.0 and so on
    public float ratioAspect;

    private void Start()
    {
        float targetaspect = ratioAspect;
        float windowaspect = (float)Screen.width / (float)Screen.height;
        float scaleheight = windowaspect / targetaspect;

        Camera camera = GetComponent<Camera>();

        // if scaled height is less than current height, add letterbox
        if (scaleheight < 1.0f)
        {
            Rect rect = camera.rect;
            rect.width = 1.0f;
            rect.height = scaleheight;
            rect.x = 0;
            rect.y = (1.0f - scaleheight) / 2.0f;
            camera.rect = rect;
        }
        else
        { // else add pillarbox
            float scalewidth = 1.0f / scaleheight;
            Rect rect = camera.rect;
            rect.width = scalewidth;
            rect.height = 1.0f;
            rect.x = (1.0f - scalewidth) / 2.0f;
            rect.y = 0;
            camera.rect = rect;
        }
    }
}

People who have extra wide monitors do not play games that require square or vertical game areas. :slight_smile:

That’s a dangerous assumption to make. When I buy a monitor, I definitely don’t think which games I’ll want to play for the next 5 years.

https://store.steampowered.com/hwsurvey/Steam-Hardware-Software-Survey-Welcome-to-Steam

In the list at the bottom you can click on display resolution. Very good to see what people actually use. 75% is 16:9

1 Like

Where are we with this?

If you need this to test your local builds, just implement a PostProcessBuild step where you delete the registry keys. The next time you start your game, it will use the defaults.

This was addressed in 2020.1. If you change a default setting in the ediitor, the first time you launch the build it will force those settings.

4 Likes

Ah, I need to test that, thank you. :slight_smile: