Keeping scale when switching to portrait mode.

Godot Version

4.5 beta2

Question

I have 2d game in landscape mode. I'd like to introduce switching from landscape to portrait anf vice versa.
The UI looks fine in editor in portrait mode (I just resize main control node in scene)

But when I run the game on mobile and switch from landscape to portrait with

if (current == DisplayServer.ScreenOrientation.Landscape ||
			    current == DisplayServer.ScreenOrientation.ReverseLandscape)
{
	DisplayServer.ScreenSetOrientation(DisplayServer.ScreenOrientation.Portrait);
}
else
{
	DisplayServer.ScreenSetOrientation(DisplayServer.ScreenOrientation.Landscape);
}

(Or just DisplayServer.WindowSetSize(new Vector2I(720, 1280)); for desktop) -
The actual scale(?) is off, so th UI is clearly different from how it looks in editor.

Stretch is set to Canvas Item + Expand.

Node setup:

So, how do I properly handle switching from landscape to portrait and back?

What happens if you start with the portrait mode? Not by switching it to portrait mode, but actually adjusting and saving the MainMenu size to be 720x1280 when you start the game.
Is it still off, or fine then?

When I actually set 720x1280 portrait in settings and set the scene as 720*1280 - everythings fine for portrait mode, but now the landscape mode is not properly scaled(

I can’t test it myself unfortunately, but here someone suggested to try designing your UI in the square e.g. 1024x1024, which is supposed to make it look the same on both portrait and landscape modes when scaled. Can you maybe try that?
https://www.reddit.com/r/godot/comments/kncasn/pro_tip_for_mobile_landscape_and_portrait_mode/

Well, the ACTUAL thing that I was looking for was

Stretch Mode → Disabled

This way the UI in game really is the same as in editor. But as the tooltip says - it doesn’t really fit games, as setting the mode to disabled brought more chaos to the the gameplay scenes than it did good to UI scenes.

The tip about designing in a square actually works, but I believe only for UI, as I had to set the WxH in settings to like 1000x1000 and again - it still gives a nuances to the non UI scenes, but still surprisingly better than a Stretch Mode → Disabled

1 Like