Unity Basics Course: Adjusting Game Screen Resolution

In game development, screen resolution is an important factor that significantly affects the user’s gaming experience. If the resolution is not properly adjusted, the screen may appear torn or stretched, which can negatively impact the immersion of the game. In this article, we will take a closer look at how to adjust the game screen resolution in Unity.

1. Understanding Resolution

Resolution refers to the number of pixels displayed on the screen, typically expressed in the form of width x height in pixels. For example, a resolution of 1920×1080 means a screen with 1920 pixels in width and 1080 pixels in height. Higher resolution provides more detail and sharper images, but it also consumes more system resources.

2. Resolution Settings in Unity

Unity offers several ways to set resolution. It provides various features to adjust the resolution according to different platforms, so understanding this is necessary.

2.1. Setting Game Window Resolution

To set the resolution in Unity’s game view, follow these steps:

  1. Select ‘Window’ -> ‘General’ -> ‘Game’ from the top menu of the Unity Editor.
  2. Find the resolution dropdown menu in the upper right corner of the game view.
  3. Select a default resolution option or click ‘Add Resolution…’ to add a custom resolution.

2.2. Changing Resolution in Build Settings

You can change the resolution when building the game:

  1. Select ‘Build Settings’ from the File menu.
  2. Choose the target platform and then click ‘Player Settings…’.
  3. In the Inspector window, find the ‘Resolution and Presentation’ section.
  4. Here, you can set the resolution and screen mode (fullscreen, windowed, etc.).

3. Adjusting UI for Different Resolutions

Adjusting UI elements to match the game screen’s resolution is very important. Unity provides the ‘Canvas Scaler’ component that helps display UI elements appropriately across various resolutions.

3.1. Setting Canvas Scaler

To set the Canvas Scaler component:

  1. Select the Canvas object and click the ‘Add Component’ button in the Inspector.
  2. Select ‘Canvas Scaler’ from the ‘UI’ category.
  3. Change the UI Scale Mode to ‘Scale With Screen Size’.
  4. Set the Reference Resolution to your desired resolution and select the appropriate Screen Match Mode.

3.2. Handling Different Aspect Ratios

To ensure the game displays correctly on various aspect ratios, UI elements should be anchored and pivoted for proper placement. This way, the UI layout stays natural even when the resolution or aspect ratio changes.

4. Using Scripts for Resolution Adjustment

Developers can use scripts to dynamically change the resolution. This allows adding functionality to change resolution during game runtime.

4.1. Resolution Change Script


using UnityEngine;

public class ResolutionManager : MonoBehaviour
{
    void Start()
    {
        // Set initial resolution
        Screen.SetResolution(1920, 1080, FullScreenMode.FullScreenWindow);
    }

    public void ChangeResolution(int width, int height)
    {
        Screen.SetResolution(width, height, Screen.fullScreen);
    }
}

The above code sets the default resolution to 1920×1080 when the game starts and shows how to change the resolution using the `ChangeResolution` method.

5. Testing Resolution on Various Devices

Testing different resolutions during game development is essential. It is important to set various resolutions within the Unity Editor to check results or to build and test on actual devices.

5.1. Testing in the Editor

Testing at multiple resolutions in Unity can be easily done by changing the resolution in the ‘Game’ view. After adjusting various settings, check how gameplay performs at each resolution.

5.2. Testing on Actual Devices

For mobile games, it is important to test on actual smartphones and tablets. You should run the game on devices with various screen ratios and resolutions to ensure the UI and graphics display correctly.

6. Optimization Tips

When adjusting the game’s resolution, performance optimization should also be considered. Games that support high resolutions consume more system resources, so here are some tips for optimization.

  • Provide users with the option to select resolution through graphic quality settings.
  • Use aspect ratio-appropriate textures to prevent distortion when adjusting resolution.
  • Set appropriate polygon counts and LOD (Level of Detail) to improve performance.
  • Dynamically load and unload UI elements to save memory.

Conclusion

In this tutorial, we learned about adjusting game screen resolution in Unity and optimization tips. The resolution of the game screen significantly impacts user experience, so developers must carefully consider this. It is essential to test at various resolutions and strive to provide the best experience to users. We hope you can develop high-quality games using Unity’s diverse features.

References