Rescaling the game

Hello everyone!

I was looking for tutorials and examples but I still have some specific doubts:

I understand that the resolution is changed with “SetResolution” and this works for me. Since the HUD that I have designed inside the “Canvas” is perfectly rescaling. But what about different resolutions and aspect ratios? Should I only allow resolutions with a 16: 9 aspect ratio? Does anyone with a resolution of 1920x1080 will see more of the scene than someone with a lower resolution?

I think the information I lack about this is very basic. I apologize if the question is very silly. But thank you very much for answering me

Thank you very much for reading and answering. Greetings

You can see it for yourself by clicking the aspect ratio button in the game view. As you see, I’ve set up some custom resolutions of common devices.

Based on that you can make your decision. On quick projects I just scale the canvas with screen size, but on more serious ones I properly use anchors.

Hi DroidifyDevs, thanks you for your quick answer!

I think I forget one important detail. My project is 2D, I use sprites. Do I have to put GameObjects having sprites (player, enemies, etc) within the canvas and let the canvas automatically rescale all?

PD: To change the resolution I do this, with a button and a dropdown, and a text debug:

    void Awake()
    {
        resolutions = Screen.resolutions;

        resolutionDropdown.options.Clear();
        List<Dropdown.OptionData> listDropdown = new List<Dropdown.OptionData>();
        for (int i = 0; i <= resolutions.Length - 1; i++)
        {
            Dropdown.OptionData optionDropdown = new Dropdown.OptionData();
            optionDropdown.text = resolutions[i].ToString();

            listDropdown.Add(optionDropdown);
        }
        resolutionDropdown.AddOptions(listDropdown);
        displayInfo();
    }

    public void onButtonPressed()
    {
        Screen.SetResolution(resolutions[resolutionDropdown.value].width, resolutions[resolutionDropdown.value].height, fullscreenToggle.isOn, resolutions[resolutionDropdown.value].refreshRate);
        cameraUsed.orthographicSize = Screen.height / pixelsToUnits / 2;
        displayInfo();
    }

    void displayInfo()
    {
        debugText.text = "Resolution: " + Screen.currentResolution.width + "x" + Screen.currentResolution.height + "\nRefresh Rate: @ " + Screen.currentResolution.refreshRate + "hz " + "\nFullscreen: " + Screen.fullScreen + "\nCamera Size: +" + cameraUsed.orthographicSize.ToString();
    }

But something goes wrong. Since I have to press the button twice. Because the first time only modifies the resolution. And the second time I press it changes the text and objects that are not part of the HUD.

Unity automatically resizes the game to fit any screen size or resolution. I really see no reason to make the user manually pick resolution.

The game’s sprites do not have to be in a canvas; in fact I can go as far as to advise against that.

Mmmh. The typical thing is that games allow you to choose the video settings from within the game, or not? I was doing it just for that reason.
But equally, do not I have to change the size of the camera depending on the resolution chosen?

Sorry for all the doubts. But it is a subject that never investigates in any other motor

Again, you can see the answers to most of your questions with the image I showed you. Play around with the game view resolution and see if you need to change anything. Unity automatically changes the camera for you, however this may lead to unexpected game views so check many resolutions. As you see I’ve made a bunch of mobile device resolutions so I can see what my game looks like on an iPad Pro or a Samsung S7 or a cheap BLU Advance.

Usually games have resolution settings for performance reasons only. If someone has a terrible computer, they might want to run at 480 or 720p. You should always design the game to fit your target resolutions, as most people play full-screen 1080p or even 4K.

Yes, I think I understood. Thank you very much for all your information. I guess I’ll have to do the game in 16: 9 and then see how it will look in different resolutions. I would like to give the performance option to the user. Do you have any idea why my code works incorrectly? As I say, the first time I press the button, the resolution is changed, and I have to press it once again to change the objects that are not part of the canvas and the text where I show in what resolution is.