The _ready()
function is called when a node enters the scene tree, which is a good time to find the size of the game window:
GD script
func _ready(): screen_size = get_viewport_rect().size # Godot 3 @onready var screen_size: Vector2i = get_viewport().size
C#
public override void _Ready() { ScreenSize = GetViewportRect().Size; }