How can I change Project-Window-Size using GDscript?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Lejardo

I set Project-Window-Size 1600x900, looks pretty.
Then I reset Project-Window-Size 1024x600, also looks great.

But wirld things happend…
When I set Project-Window-Size 1600x900, and use code below changing it to 1024x600, it looks terrified, seems also resize all the label text together.

pics here:

This is “Using Project-Window-Size” set 1024x600, looks good:

This is "“Using Project-Window-Size” set 1600x900, then use script change to 1024x600, looks sad (label text automaticly scaled):

I’ve tried these codes, none can change project-window-size like pic1

OS.set_window_size(Vector2(1024,600))
get_viewport().set_size_override(true,Vector2(1024,600),Vector2(0,0))
$"/root".size=Vector2(1024,600)

So, how can I change window-size, like changing from Project-window-size effect, using code?

I find out there is “display/window/size/width”,“display/window/size/height” in Project-Window-Size, how can I change these vales using GDscript?
Have been confused for couple of days…

Thank God may somebody help me out…

Lejardo | 2018-10-20 15:19

It looks when using script “OS.set_window_size(Vector2(1024,600))” , it just scale the resolution which project-window-size set, to 1024x600, that is:

if Project-window-size set 1920x1080, then use script above, it just scale the 1920x1080 view to 1024x600, scale all the UI (button, text, etc…).

It looks very different to Project-window-size set 1024x600.

Lejardo | 2018-10-20 15:55

:bust_in_silhouette: Reply From: Calinou

As described in the Multiple Resolutions documentation, you should change the Stretch Mode from disabled to 2d and set the Stretch Aspect to expand in the Project Settings.

Thank you.
I don’t know wether I’ve myself clear, or you’ve test it already and works?

I’ve did as you said, but still can’t get what I expected.

What I want is:
Using code change resolution, without scaling buttons, labels…etc.
Just like change resolution from Project settings.


As you see, I set Project resolution to 640x480, and works perfect.
The button size, label text is the size I’ve set, so clear.


But when I set Project resolution to 1600x900, and using code to change the resolution to 640x480, it turns into hell…
Look the button size and label text…

I just wanna find a way to using script change resolution, just like change it in Project settings, without scaling up or down UI elements.

My working resolutiong is 1600x900, I wanna using code change it to any other resolution, like 640x480, just like the effect changing in Project setttings.
NOT THIS KIND of UI scaling up and down.

Lejardo | 2018-10-21 02:46

“Multiple Resolutions” link

smaran | 2021-05-18 19:52

:bust_in_silhouette: Reply From: surferlul

if you’re working on a Panel (or any control node based node) you can scale it through rect_size().x *= scale_factor. This will scale any child node of it.

:bust_in_silhouette: Reply From: Hamion

If you use the Stretch Mode Viewport instead of 2d, you should get your desired reuslt.