- Home /
Constant UI elements size
Hello, I am new in unity. Now I want to create UI for my task, but I have a problem with scaling, so my question is how I can provide a constant element (buttons, drop-down lists, etc.) size, which depends on DPI. For example, now, when I try to resize my window, the elements are also resized too. I also want to provide resizing of elements from the script. So what is the best way to solve this problem?
Answer by Patrickmol · Jun 10, 2021 at 11:01 AM
If you click on a GUI object with the tool that you are using in the picture above you should see the ancor points, just drag them to fit the elemnt size and it will remain that on all the resolutions ;D YOU CANT DO THIS TRICK WITH SLIDERS HANDLE OR LAYOUT GROUPS.
But the size of elements still depends on the size of the window, I want to make constant size, for example, button size is equal 3cm and for all monitors and all resolutions, it must be equal 3cm (we know DPI value)
Answer by DenisIsDenis · Jun 10, 2021 at 11:45 AM
To make a UI element independent of the size of the screen:
1) Select the UI element.
2) Set the required Anchor Preset (the ones I highlighted will work in your case):
Thanks, but as I answered before, the size of elements still depends on the size of the window. I want to make constant size, for example, button size is equal 3 x 3 cm and for all monitors and all resolutions, it must be equal 3 x 3 cm (taking into account that we know DPI value)
This might help: Select the Canvas and change the UI Scale Mode to Constant Physical Size: