unproject_position and is_position_in_frustum returns wrong results if window is resized to a different aspect ratio

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By mayonnace

I have 1920x1920 viewport size and 640x400 window override size in project settings. Using a 1:1 default aspect ratio helps preventing GUI elements changing their relative sizes, and also, it’s a recommended setting for supporting both landscape and portrait screens, written in one of the green tip boxes at Multiple resolutions — Godot Engine (stable) documentation in English.

Unfortunately, camera.unproject_position() and camera.is_position_in_frustum() functions don’t seem to return correct results if the window’s current aspect ratio is different than of the viewport width and viewport height values set in the project settings.

How may I get correct results with these functions for all possible aspect ratios?

I don’t want the game to malfunction if the player resizes the window or plays it in fullscreen on a different aspect ratio, you know.

Thanks in advance!

If functions are not working as expected, you can report it on Github: Issues · godotengine/godot · GitHub

putper | 2023-06-06 00:06