1
\$\begingroup\$
  • Added screen resolution settings

  • Change screen resolution in game

  • Everything is already anchored

  • GUI gets the hell out of the screen, moves around and goes everywhere

Screenshots at different resolutions with UI laid out differently

\$\endgroup\$
1
  • \$\begingroup\$ inb, yes i did read the docs, yes i did read the posts of other people asking the same thing, yes i did watch and read tutorials, yes i did use the Demo on UI scaling offered by the godot engine creators... no, nothing fixed the issue and people on reddit are gaslighting me saying this is normal and it's how "correct UI" is supposed to behave \$\endgroup\$ Commented Dec 16, 2023 at 20:06

1 Answer 1

1
\$\begingroup\$

This is the approach I take at the time of writing:

  • I set stretch modo to canvas_items in Project Settings -> Display -> Window

  • I organize the main scene like this:

    Main (Control)
    ├ World (Control)
    │ ├ Background (if necessary)
    │ ├ SubViewportContainer
    │ │ └ WorldViewport
    │ │   └ (load world scene here)
    │ └ Postprocessing (if necessary)
    └ UI (Container)
      ├ HUD (Control)
      └ (Menus, loading screen, etc)
    
  • I design the UI to the window size I have configured in Project Setting, and due to the stretch mode, it scales with the Window/Screen.

  • The resolution for the game is separate since it is on a separate viewport, this way I can offer settings to change that resolution without affecting the UI.

Notes:

  • I do not use the Godot's API to change scenes. This has tradeoffs that I'll not go into here, but yes... It requires more code.
  • I took the idea of putting the game world in a separate viewport from this video: How to make a silky smooth camera for pixelart games in Godot (3.x).
  • I have not incorporated settings to allow the user to customize the scaling of the UI in my games at the time of writing. However, as you has found out, changing the main resolution scales the UI, and having the game in a separate viewport would have its resolution unaffected by that, and with proper use of containers/anchors you could keep it on the correct position on screen (or you can always throw some code on resize).
  • I would probably continue to evolve this in the future. So, I'm not saying this is the definite solution. However, I'm saying this approach solve the problem at hand, and you probably can adapt it to your needs.
  • How does the game world communicate with the HUD? You can use an autoload for that, although I have moved to static code (The solution to How to write a static event emitter in GDScript? has proven useful). In general, I'm avoiding autoloads so my code needs less setup to reuse from project to project. With that said, I also want to point out I'm aware of developers doing everything in autoloads so they can keep using Godot's API to change scenes.
\$\endgroup\$

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.