The default ViewPort size in Project Settings is 1152 X 648.
I want to change the viewport size to a custom size stored in a Vector2 variable, without changing the default value in Project Settings. I have set the stretch settings I want for the project:
when you change project settings directly like that, iirc you have to restart the project aka reopen it but if you reopen it, it will reset back the value again, so nothing will ever change
But to set window size of your game, you do it from DisplayServer.window_set_size()
It still does the same thing as get_viewport().size. The window size has changed but the aspect ratio did not…
I was actually trying to follow the intro to gdscript 2 tutorial by GDquest. He uses get_tree().set_screen_stretch(......) in godot 3. I couldn’t find this method even in the documentation of godot 4.
In the tutorial, the in-game resolution changes with the window size:
i always suggest people to learn from the same engine major version, if you are very new to godot. trying to convert godot 4 to godot 3 or the other way will make you come to this place and ask. which is correct to do. but really it can be avoided if you just learn from godot 4 tutorials directly.
but ok, what you are looking for is the set_screen_stretch on godot 4, which is actually this on project settings: