Change the game resolution

Page update date :
Page creation date :

Verification environment

Windows
  • Windows 11
Unity Editor
  • 2021.3.1f1
Input System Packages
  • 1.3.0

Prerequisites for this tip

The following settings are pre-configured as a prerequisite for the explanation of these tips.

Specifying the resolution at the start of the game

You can set the resolution at the start of the game from the project settings. However, there are restrictions such as window mode assumptions, so if you want to set it reliably, I think that the setting by the program described later is more reliable.

To do this, select Edit -> Project Settings from the menu.

Select "Player" from the menu on the left.

At the bottom, you can find the settings for each environment. For example, if the display icon on the far left is the setting of the PC environment such as Windows.

"Resolution and Display" is collapsed inside, so click to expand it, and select "Windowed" from "Full Screen Mode" in the resolution group.

Then "Default screen width" and "Default screen height" will be displayed, so you can set the resolution (= screen size) here. This setting can only be set in windowed mode.

There are settings in other environments, so please check them. The following diagram shows the configuration in WebGL. Resolution = size of the canvas.

Run and verify

I can't check if it's correct even if I run it in the Unity Editor, so I'll output the game and check it. For detailed instructions, see the Tips for Game Output .

Make sure that it is displayed on the specified screen size.

However, even if you change the size value, the size may not change. This is because the game itself remembers the previous resolution. If you want to make sure that the display is at the specified resolution, it is more reliable to change it with the program described below.

Change the resolution from the program

Here, I would like to prepare the following screen and control it programmatically so that the resolution changes when each button is clicked. For more information on how to handle UI and buttons, see UI Tips .

Here's what happens when you click each button:

using UnityEngine;

public class ButtonEvent : MonoBehaviour
{
  public void OnClick_960x540()
  {
    // 横幅 pixel、縦幅 pixel、ウィンドウモード、リフレッシュレート(Hz) を指定
    // ウィンドウモードの場合、ウィンドウサイズも変わる
    Screen.SetResolution(960, 540, FullScreenMode.Windowed, 60);
  }
  public void OnClick_1280x720()
  {
    // 横幅 pixel、縦幅 pixel、ウィンドウモード、リフレッシュレート(Hz) を指定
    // ウィンドウモードの場合、ウィンドウサイズも変わる
    Screen.SetResolution(1280, 720, FullScreenMode.Windowed, 60);
  }
  public void OnClick_1600x900()
  {
    // 横幅 pixel、縦幅 pixel、ウィンドウモード、リフレッシュレート(Hz) を指定
    // ウィンドウモードの場合、ウィンドウサイズも変わる
    Screen.SetResolution(1600, 900, FullScreenMode.Windowed, 60);
  }
}

For the bottom two methods, the only difference is the resolution number.

Screen.SetResolution You can change the resolution by specifying "resolution width (px)", "resolution height (px)", "full screen mode", and "refresh rate (Hz)" in the method arguments, respectively.

This time, it will be set in windowed mode, but it can be set in the same way in full-screen mode.

If you want to force it to be set when the game starts, I think you can handle it with a script method attached to some object in the awake first scene.

Run and verify

I think you can see that clicking each button changes the resolution (+ window size).