How to prevent automatic GUI scaling?

By default the GUI is always scaled when the target’s device resolution is different from the one defined in the project file.
This is good for most mobile devices because it ensures that the game always looks similar on various devices.

But on PC that’s a different story. Here i want my GUI to stay at it’s defined size and not scale upwards when i go fullscreen. Given the precision the user has with it’s mouse compared to touch, such massively upscaled GUI-elements can look and feel quite strange on big screens.

So how can i setup my project and/or render script that it scales the GUI on mobile devices but not on desktop devices like pc, mac and linux? In the GUI-Editor i can only select “Fit”, “Stretch” and “Zoom” for the adjust mode, but not “None”…

I ran into a similar issue. +1 on a “None” option. The way I solved it is by inferring the scale of the gui in the render script, sharing it globally, and then applying the inverse of that scale to every gui element in the gui script.

-- in .render_script update
-- share gui scale globally so that we can reverse it in our gui script (this blackboard is my own thing, you can use a global table)
-- this guess at the gui scale assumes that "fit" adjust mode is used on all elements whose scale you want to override
blackboard.set(global_blackboard, "gui_scale", math.min(render.get_window_width() / render.get_width(), render.get_window_height() / render.get_height())
-- in .gui_script update
local gui_scale = blackboard.get(global_blackboard, "gui_scale", 1)
local inverse_gui_scale = vmath.vector3(1 / gui_scale, 1 / gui_scale, 1)
-- collect all of the gui elements that you want to be unscaled via some method of your own
for k, v in pairs(gui_elements) do
    gui.set_scale(v, inverse_gui_scale)
end
1 Like

What about setting size mode to manual ?

Thank you very much, that seem to work for my case. I will fully implement it for all my buttons tomorrow.

I guess instead of resizing my gui in every update cycle i can do the resizing only when a window_resized message is received?

@Deividas_Krunkauskas:
I tried that yesterday, but had no success.

1 Like

Ideally, yeah. Let me know if that works :+1: I didn’t have time to optimize when I came up w/ this technique.