Ui not resizing properly with the screen

Godot Version

4.2.2

Question

my stretch settings are canvas items and expand. since i want to release this on mobile as well as pc (and probably web too), just disabling stretching seems like a bad move.

this is the code for my hud:

extends Control

func _process(delta):
	size=get_viewport().size
	position.x = get_parent().get_node("Camera2D").position.x - get_viewport().size.x/2
	position.y = get_parent().get_node("Camera2D").position.y - get_viewport().size.y/2
	#custom_minimum_size=get_viewport().size

func _on_pause_button_pressed():
	get_tree().paused= !get_tree().paused

my hud isn’t the child of my camera2d node

for reference this is what it looks like while the screen is in the default size and what it’s supposed to look like:

this is what it looks like when the screen size is less than default:

and here’s what it looks like when the screen size is bigger (the hud is getting cut off)

You shouldn’t need to set the UI size every frame, the anchor mode “Full Rect” should scale with the canvas, maybe you need a CanvasLayer as a parent of your UI?

1 Like

Yeah you don’t need to do any calculations or sizing yourself, the engine will do it for you. Except in some certain cases where the Godot is just broken.

Also please post a screenshot of your project settings for the window.