Hi

How through a script to change the viewport size of the screen?
I tried to make it through :

        ProjectSettings.set_setting("display/window/size/viewport_width", int)
	ProjectSettings.set_setting("display/window/size/viewport_height", int)

But it does not work.

func _ready():
	
#	To change screen permission in basic settings (viewport)
	ProjectSettings.set_setting("display/window/size/viewport_width", 800)
	ProjectSettings.set_setting("display/window/size/viewport_height", 600)
	
#	To show  screen size (viewport)
        print(str(ProjectSettings.get_setting("display/window/size/viewport_width")))
	print(str(ProjectSettings.get_setting("display/window/size/viewport_height")))
#	To show screen size 
	print(str(DisplayServer.window_get_size()))
  • IGA22 You are looking to change the wrong property then, that has nothing to do with window size.

    The easiest solution would be to have a separate viewport container and viewport you would render your 3D scene/camera output to. And change that viewports resolution.

IGA22 changed the title to How through a script to change the viewport size of the screen? .

DaveTheCoder

In versions Godo 4.x it does not work.

instead of it now correctly so, and this team does not change the basic size
DisplayServer.window_set_size(Vector2i(int, int))

I need to change variables which belong to the class ProjectSettings - display/window/size/viewport_width , display/window/size/viewport_height

In GODO two sizes, one basic (pixels), the second is responsible for a ratio of the parties

https://docs.godotengine.org/en/stable/tutorials/rendering/multiple_resolutions.html <=


I overlooked the Godot 4.x tag in your post. I only tested the code using Godot 3.5.1.

What are you trying to change? There is the window size, which is the physical size of the app window on the screen in pixels. When you go full screen, it is typically the native resolution of the monitor. You can also adjust the viewport size to be larger or smaller than the native resolution, useful for pixel art games. Or you can use filtering or upscaling, using bilinear or FSR, to upscale a smaller size viewport to native resolution of the monitor or window to improve performance at minor quality loss. But what is your goal?

I want to know how to change the size for increase in performance in 3D projects in Godo 4.x

                                        size       1920 x 1080

                                        size        800 x 600

    IGA22 You are looking to change the wrong property then, that has nothing to do with window size.

    The easiest solution would be to have a separate viewport container and viewport you would render your 3D scene/camera output to. And change that viewports resolution.

    I did not know about viewport container, but looked for something similar.
    Hope it what is necessary.

    Correct. The property is called scaling_3d_scale

    a year later

    Why was that the wrong question? I too would like to know how to change the viewport size programmatically with Godot 4. It's my first project.

    As I understand it, viewports are sized by whatever contains them (usually the main window).