Only allowing windowed mode and 1:1 aspect ratio in my game?

I’ve been trying to build my game without any fullscreen capabilities. I want this game to only be played in the 1:1 aspect ratio.

When I build my game the game suggests resolutions that are not 1:1. How can I fix this?

Thanks in advance!

Change Your Player Settings

Navigate to Edit > Project Settings > Player and just uncheck everything you don’t want.

It’s actually better if you do not restrict the different resolutions too much. It might result in worse device support if you try to enforce a certain window mode. It’s better to allow any resolution and just “letterbox” your camera so it has a 1:1 ratio.

You can use a simple script like this:

// CameraLetterBox.cs
using UnityEngine;

public class CameraLetterBox : MonoBehaviour
{
    public Camera backgroundCam;
    public Camera mainCam;
    public float targetAspectRatio = 1f;

    private void Start()
    {
        if (mainCam == null)
        {
            mainCam = Camera.main;
            if (mainCam == null)
                mainCam = GetComponent<Camera>();
        }
        if (backgroundCam == null)
        {
            foreach (var cam in Camera.allCameras)
            {
                if (cam != mainCam)
                {
                    backgroundCam = cam;
                    break;
                }
            }
            if (backgroundCam == null)
            {
                backgroundCam = new GameObject("BackgroundCam").AddComponent<Camera>();
            }
            backgroundCam.depth = mainCam.depth - 1;
        }
    }
    private void Update()
    {
        float w = Screen.width;
        float h = Screen.height;
        float a = w / h;
        Rect r;
        if (a > targetAspectRatio)
        {
            float tw = h * targetAspectRatio;
            float o = (w - tw) * 0.5f;
            r = new Rect(o,0,tw,h);
        }
        else
        {
            float th = w / targetAspectRatio;
            float o = (h - th) * 0.5f;
            r = new Rect(0, o, w, th);
        }
        mainCam.pixelRect = r;
    }
}

This script allows you to specify a desired aspect ratio for the main cam. It will center the main camera rect on the screen and if the screen is too wide it will put a letterbox on both sides. If the screen is too high it will letterbox above and below the cam rect.

Of course when a letterbox is required there will be unused space. That’s why there should be another “background” camera which just clears the whole screen before the main cam so the letterbox area get either cleared with a color or an image / texture.

I would allow to resize the window. I personally hate games which force you to a certain resolution or fullscreen setting. That’s something the user should decide. Also restricting the display resolution dialog wouldn’t be enough. The Unity player supports command line parameters to force certain settings. So if your game requires a certain aspect ratio it’s better to inset the desired aspect ratio inside the available space. That way you can ensure to have the correct ratio, no matter the resolution.