How to set the window size in Godot 4: get_window().size
By Eduardo Orellana · Updated
Set get_window().size = Vector2i(1280, 720) in code, or set the default in Project Settings, Display, Window, Size. Godot 3's OS.window_size is gone: it fails to parse with Cannot find member "window_size" in base "OS".
AppImage, x86_64. Ubuntu 22.04, Debian 12, Fedora 39 or newer.
Intel or AMD Chromebook, with Linux turned on.
What Godot is checking
Godot 4 moved window control off OS. Each window is a Window node, the game's main one is get_window() from any node, and its size, position and mode are its properties. DisplayServer offers the same calls by window id.
The size is a Vector2i, in pixels. This page's run is headless, with no real window, and shows the Window node taking the size.
Reproduce it
A Godot 3 window size, in a Godot 4 project.
extends Node
func _ready():
OS.window_size = Vector2(1280, 720)
What Godot 4.7.2 prints
Godot Engine v4.7.2.stable.mono.official.ed1daf0bf - https://godotengine.org
SCRIPT ERROR: Parse Error: Cannot find member "window_size" in base "OS".
at: GDScript::reload (res://answers/how-to-set-the-window-size-in-godot-4/repro.gd:4)
ERROR: Failed to load script "res://answers/how-to-set-the-window-size-in-godot-4/repro.gd" with error "Parse error".
at: load (modules/gdscript/gdscript_resource_format.cpp:46)Fix it
Set the main window's size and read it back.
extends Node
func _ready() -> void:
get_window().size = Vector2i(1280, 720)
print(get_window().size)
What the fixed script prints
Godot Engine v4.7.2.stable.mono.official.ed1daf0bf - https://godotengine.org
(1280, 720)Verified on Godot 4.7.2
Both scripts on this page were run headless on Godot 4.7.2 (4.7.2.stable.mono.official.ed1daf0bf) on 18 October 2026, and the output above is what Godot printed, unedited.
Where the check lives in Godot's source: [gdscript_analyzer.cpp line 4122, the message](https://github.com/godotengine/godot/blob/4.7.2-stable/modules/gdscript/gdscript_analyzer.cpp#L4122), [Window.size in the class reference](https://github.com/godotengine/godot/blob/4.7.2-stable/doc/classes/Window.xml).
Questions
- How do I make the window fullscreen?
- get_window().mode = Window.MODE_FULLSCREEN, or DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_FULLSCREEN).
- How do I keep the game the same size on any window?
- Set Project Settings, Display, Window, Stretch, Mode to canvas_items or viewport, and pick an aspect.
Related
- Cannot find member "…" in base "…"
- How to get the current date and time in Godot 4
- Every verified Godot 4 answer
- WindowDialog in Godot 4: it is Window now
- Function "…()" not found in base self in Godot 4
- Cannot get return value of call to "…()" because it returns "void" in Godot 4
- Reference in Godot 4: it is RefCounted now
- Spatial in Godot 4: Could not find base class "Spatial"
Flockbay's agent reads Godot's debugger output and fixes errors like this one in your project, on the official Godot.
Download Flockbay free