Is there a way to lock the window or root aspect ratio?

Godot Version

4.3

Question

I have tried various things, such as this guy’s code I found a script to maintain the window's aspect ratio. How do I fix this final bug?

However no matter what code I try to use to control the window size, I get consistently bad results (worse than the guy in aforementioned post, I suspect it’s gotta do with OS differences, I’m using wayland(:nauseated_face:) on linux so there could be a causation of some kind there)

However I do not actually need to force the window itself to an aspect ratio, it would be sufficient for me to force the root to an aspect ratio, now normally you can do that by using the stretch display settings under the project settings:

However in order for that to work you must actually be using a stretch mode which scales the root in a way I do not want, because it’s incompatible with my svg scaling shenanigans.

The main reason I want to be able to lock the aspect ratio is for relative positional data when scaling the window (if the aspect ratio is locked, I can reliably control the x and y position of a sprite based on it’s distance to the window’s edges, however if it is not locked I can only somewhat reliably do it for the Y axis)

Although if I cannot lock the actual window nito an aspect ratio reliably then i’d have to change the code a little bit but it should be doable…


This should keep the game_pixel_units per window size consitant if thats what you need. If you want to have always the same game_pixel_unit distance from a sprite to the border of the game window you have to set the aspect to keep. Now your game_pixel_units in width and height are always the same no matter what resoulution you set your gamewindow to. I hope that helps solving your problem.

That isn’t what I need, I already knew how to do that, i even outlined it in the linked thread.

I only need it to lock the aspect ratio, i do not need the stretch functionality.

For what it’s worth, I did eventually give up on that approach and I just made a responsive UI and used the WindowSizeManager to set a minimum window size. I sincerely apologize for the hours spent getting my code to do the thing it was never very good at.

1 Like

That’s depressing, considering many other game engines have this sort of functinoaltiy built in (like rpgmaker and i think even unity might actually have it too, i feel like i’ve seen it in some unity games)

I guess making a responsive UI is kind of a better solution though, just takes more time.

Use this to turn off resizing.

func _ready():
	get_window().unresizable = true

That’s an interesting feature, it is an alternative but a very poor one, few game design decisions are worse than making a game window unresizable.

I know from experience, from trying to play such games.

I suppose it could be used to lock the window to specific resolutions which you can only set through the menus which would lock the aspect ratio though (that’d be somewhat acceptable I suppose), but I don’t want to do that, I want it to be drag resizable.

Yeah, that how it can be used.

What do you mean by that?

click on the edge of the window and drag it to resize it.

1 Like

Take a look at my post here, maybe this can help : here